Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

1 Answer 1

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"
end
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.