Using a simple “script” at the command line, you can rename a bunch of similar filenames with ease. Say you’ve got something like: foo-001, foo-002 and foo-003, but you want them to be bar-001, bar-002 and bar-003. The script will look like :
$ for i in `ls -1 foo*`; do mv $i `echo $i |sed -e 's/foo/bar/'`; done
You can test your code without making changes by removing the ‘mv’ command and just echoing the results to stdout like so :
$ for i in `ls -1 foo*'; do echo $i |sed -e 's/foo/bar/'; done
With the latter command, you can examine the results to see if that’s actually what you want ‘mv’ to rename the files to.
How to Rename Similar Files at the Command Prompt Using Sed
Posted on