rename is a program that renames files according to modification rules specified on the command line.
##
# `rename.pl` commands
#
# NOTE: `-n` = dry run.
##
# sanitize
rename -n -z *;
# Remove single quote marks
rename -n -e s/\'//g *
# Replace existing file extension (.txt) with another file extension (.cs):
rename -n -e 's/\.txt$/\.cs/g' *;
# Remove commas
rename -n -e 's/,//gx' *
# Remove last underscore before file extension '_.pdf'
rename -n 's/_(\.[A-Z-a-z]{3}$)/$1/g' *;
# convert to lowercase (-X/--keep-extension)
rename -n -f -X -c *;
# convert to uppercase (-X/--keep-extension)
rename -n -f -X -C *;
# replace '_2.0_' with '2'
rename -n -e 's/([1-9]{1})(?:\.[0])/$1/gi'
# replace hyphens (-) with underscores (_)
rename -n 's/(-)/_/g' *;
# replace 'c++' with 'cpp'
rename -n 's/(c\+\+)/cpp/gi' *;
# replace 'c#' with 'csharp'
rename -n 's/(c#)/csharp/gi' *;
# Remove brackets
rename -n -f -S '[' '' -S ']' '' *;
# replace '_s_' with 's_'
rename -n -f -S '_s_' 's_' *;
# replace '._.' with '_' (-X/--keep-extension)
rename -n -X -S '._.' '' *;
# replace '._' with '_' (-X/--keep-extension)
rename -n -S '._' '_' -X *;
# replace dot char with underscore (-X/--keep-extension)
rename -n -X -S '.' '_' *;
# replace dot char with space (-X/--keep-extension)
rename -n -X -S '.' ' ' -X *;
# replace double underscores with single
rename -n 's/_-_/_/g' *;
# Remove 'the last dot in the entire file/dir name'
rename -n -e 's/\.$//' *;
# Remove `-ebook` at the end of the dir/file
rename -n -e 's/-ebook$//' *;
# Remove opening and closing parenthesis `()`
rename -n -e 's/\(//gx' *;
rename -n -e 's/\)//gx' *;
# Remove opening and closing brackets `[]`
rename -n -e 's/\[//gx' *;
rename -n -e 's/\]//gx' *;
# Remove brackets "[]", exlamation points "!" and hash marks "#":
rename -n -e 's/[\[\]!#]//g' *;
# Replace duplicate spaces, with one space:
rename -n -e 's/\s\s+/ /g' *;
# Remove trailing spaces before the file extension:
rename -n -e 's/\s+(\.[^.]+)$/$1/g' *;
# Convert file extensions to lowercase:
rename -n -f -e 's/\.([^.]*$)/.\L$1/' *;
# Capitalize separate words (-X keep extension, -f force):
rename -n -f -X --camelcase *;
# Capitalize all characters in the file name except the file extension (-X/--keep-extension):
rename -n -f -X -C *;
# Rename a TV series of files, according to a season:
rename -n --counter-format 01 --keep-extension -e '$_ = "S09E$N"' *.mp4
# To rename and all *.avi files in the current directory, and move them to a new sub-directory called 'season6' (will create sub-dir if doesn't exist):
rename -n --mkpath --counter-format 01 --keep-extension -e '$_ = "season6/S06E$N"' *.avi