![]() You have several files with names like my_file.xyz and you want to rename these files so that they become something like my_file.abc. The asterisk tells you to rename matching files in the current directory.Ä«ut what if you want to rename all the matching files in sub-directories as well? In that case, you can use two asterisks like this: rename 's/ /_/g' ** Scenario 2: Change Extensions of Multiple Files at Once in Linux If you are even remotely familiar with regex, you would understand that s/ /_/g is searching for space and replacing all occurrences of space with _. To replace the spaces with underscores in the names of all the files in the current directory, all you have to do is to use renam command in this way: rename 's/ /_/g' * The rename command will be pretty handy here. Naturally, you would want to remove the spaces and replace them with an underscore (_). This is why no experienced user ever names a file with spaces in it. Itâs a nightmare to handle spaces in filenames in Linux. Imagine if you have white spaces in several filenames. ![]() Scenario 1: Replace a Character With Another in all the Filenames in Linux Let me show two practical scenarios where this command will save you a lot of time. Now you must be wondering how to rename files with the rename command. If you are a sudo user in Ubuntu or Debian, you can use this command to install rename: sudo apt install rename
0 Comments
Leave a Reply. |