Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I think the title says it all, what I need to do is loop through all images in a directory on my Ubuntu vb, check for a prefix (for example 'ql_') if it already has the prefix, I want to leave it alone, if not I want to add the prefix to the filename.

If you have time to briefly explain what you've done I would be especially grateful as I am desperately trying to get my head into Linux. (e. G what the commands you are using do)

share|improve this question
up vote 3 down vote accepted

The pattern matching operator in tcsh makes short work of this. I've used quotes around the $i substitutions in case any filenames contain spaces.

foreach i (*)
   if ( "$i" !~ ql_* ) mv "$i" ql_"$i"
share|improve this answer
Thanks Nicole, worked like a charm. I had never heard of tcsh before, seems handy. I'll have to check it out i more depth. – WebweaverD Dec 18 '12 at 16:57
tcsh is Bill Joy's Berkeley C shell. The t means it's the version that includes filename completion and command line editing. I'd start with the Wikipedia article, which is pretty good. The very best book on it is still the 1986 UNIX C Shell Field Guide even though it's a little out of date; this was the book that I kept at my side when I wrote my own C shell. – Nicole Hamilton Dec 18 '12 at 17:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .