GNU/Linux Desktop Survival Guide
by Graham Williams |
|||||
Rename File |
20200915 The basic syntax of the rename command is:
$ rename [-n|-v] 's|<regexp>|<replacement>|' * # s => substitute y => transliterate |
Numerous examples of the command are illustrated throughout this chapter. Here's some typical use cases:
# Rename backup versions using ~n~ style to numeric versions. $ rename -n 's/.pdf.~([0-9]+)~/_$1.pdf/' * rename(20201129_paper163.pdf.~2~, 20201129_paper163_2.pdf) # Remove redundant final underscore. $ rename -n 's/_\././' * rename(20201129_paper163_.pdf, 20201129_paper163.pdf) # Substitute underscore for spaces in filenames. $ rename -n 's/ /_/g' * # Replace various symbols with underscore. $ rename -n 's/[&:\(\)\[\]]/_/g' * # Remove strings of underscores. $ rename -n 's/__*/_/g' * |