I want to rename all files in a directory. The new names don't follow any pattern, so I can't use
Is there any efficient way to do this, so I won't have to use
mv foo.txt bar.txt for every single file?
When thinking about writing this as a script I checked if possible names are already taken, and turns out my guess "interactive move" is already written and ready to use. For most systems it should be available in the renameutils-package, which contains various tools which are very helpful:
The problem with
Multiple arguments will yield an error. So you'll basically have to wrap it up in a short
That is of course hard to type, so we should wrap this into a ready to use function which we can place in our
You can use this command:
It will prompt you for a new name for every file and also for every directory (
If you want to change the file name only a little bit, it's more efficient if you can edit it, starting with the old file name, as suggested by @grawity:
I tested it with filenames containing spaces and braces, however please use it on your own risk (and make a backup of the original files before).
|show 3 more comments|
#!/usr/bin/env bash for files in $( echo * ); do echo -n Rename $files to which name? ; read new_name ; mv "$files" "$new_name"; done