Return to site

Linux mass rename files pattern

broken image
broken image

Please bear in mind that the “.” after the find command denotes the current directory.Īwk is a powerful text-processing utility. In our case, all files with names containing “ backup” are targeted. The -exec argument tells find to execute rename for every matching file found. Log1-backup.xml log1.txt log2-backup.xml log2.txt log3.txt log4.txt Log1-backup.txt log1.txt log2-backup.txt log2.txt log3.txt log4.txt

broken image

It looks for the first occurrence of txt in each filename, and replaces it with log.Īlternatively, we can use rename with the find command to target specific files: $ ls The rename command is pretty straightforward.

broken image

log *.txtįile1.log file2.log file3.log file4.log file5.log Now, let’s use the rename command to rename our. This is because there is no “undo” or “restore” option for a bulk renaming operation. It is recommended to always do a dry-run to make sure that the changes are correct. The rename command with “ -nv” options shows the mistake clearly and gives us a chance to correct the command. In this example, when we typed the command line, we had an extra dot in front of the replacement “ log” by mistake.

broken image