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

Rename Files

20191229 The basic syntax of the rename command is:

$ rename [-n|-v] 's|<regexp>|<replacement>|' *   # s => substitute

Numerous examples of the command are illustrated throughout this chapter. Here's some more 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)

# 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 © 1995-2020 Togaware Pty Ltd. . Creative Commons ShareAlike V4.