Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Rename all *.gif files in a directory (prefix) (See related posts)

// My mind always seems to draw a blank when I want to do this sort of thing, so here's a concise little self-reminder

for file in $(echo *.gif); do mv ${file} prefix.${file}; done

Comments on this post

toruvinn posts on Aug 28, 2007 at 19:47
I believe there's an even easier way to accomplish this:
for i in *.gif; do mv -i "$i" "prefix.$i"; done
This should work for every file name (even with spaces). Also, I really suggest using -i there. ;-)


Also, the `rename' command might come in handy (not necessarily for adding prefixes, though) when renaming huge amounts of files.

You need to create an account or log in to post comments to this site.


Click here to browse all 5140 code snippets

Related Posts