You are here

  1. Blogs
  2. » charles's blog

Do the same thing to many files when wildcards break

This is a gem I use a lot, and forget a lot, so it's write it down time.

Suppose I have a folder with a number of tarballs in it and I want to extract all of them, tar -xf *.tar won't work as tar will try and extract all but the first file that matches the wild card from the first item. We break out the trusty for loop.


for foo in `ls *.tar`
do
tar -xf $foo
done

The above works at when entered line by line into the prompt or as part of a script. And to be even kinder, it appears in your history as for foo in `ls` ; do echo $foo; done

And yes, I was just extracting the drupal 6 versions of eveyr module I use.

And yes, I should be ashamed of myself for needing to look up a for loop in bash. I guess I'm prone to breaking out python, haskell or the dreaded perl as soon as I realise I'm going to have to write more than one line.

Subject: 

Add new comment

BBCode, html and code systax highlighting

  • Allowed HTML tags: <a><img> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd><strike><hr>
  • Lines and paragraphs break automatically.
  • You can use BBCode tags in the text. URLs will automatically be converted to links.

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.

My Band

LinuxCounter.net

Creative Commons License
Except where otherwise noted, work is licensed under a Creative Commons Licence and is the work and opinion of the credited author(s).

Powered by Drupal

My Facebook


Charles Elwood's Facebook profile