Go to TogaWare.com Home Page. GNU/Linux Desktop Survival Guide
by Graham Williams
Duck Duck Go



CLICK HERE TO VISIT THE UPDATED SURVIVAL GUIDE

Rename Files

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' *


Support further development by purchasing the PDF version of the book.
Other online resources include the Data Science Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © Togaware Pty Ltd. Creative Commons ShareAlike V4.