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


Copyright © 1995-2020 Togaware Pty Ltd
Support further development through the purchase of the PDF version of the book.
Brought to you by Togaware and the author of open source software including Rattle and wajig.
Also the author of Data Mining with Rattle and Essentials of Data Science.