I have 3 files in my current working directory as follows:
abc def xyz.tgz
ghi jkl xyz.tgz
def klm zxc.tgz
I wish to rename the files such that the spaces should be replaced with an underscore. To achieve this I used the following approach:
rename -v 's/\ /_/g' *tgz
Following are the issues:
- The command executes without any error, but no files are renamed.
When the directory contains only one tgz file, an error is observed as follows:
rename: not enough arguments
If I use the following:
rename " " "_" *.tgz
Only one occurrence of space is replaced with an underscore.
This code will find all files or directories in the current directory and replace all spaces in their filenames with underscores:
Your system seems to provide the other rename, which doesn't support Perl's substitution. You can still use it:
Or just use
mv
with parameter expansion: