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 --dry-run -z *
# Remove single quote marks
rename --dry-run -e s/\'//g *
# Replace existing file extension (.txt) with another file extension (.cs):
rename --dry-run -e 's/\.txt$/\.cs/g' ./*.txt
# Remove commas
rename --dry-run -e 's/,//gx' *
# Remove last underscore before file extension '_.pdf'
rename --dry-run 's/_(\.[A-Z-a-z]{3}$)/$1/g' *
# convert to lowercase (-X/--keep-extension)
rename --dry-run -f -X -c *
# convert to uppercase (-X/--keep-extension)
rename --dry-run -f -X -C *
# replace '_2.0_' with '2'
rename --dry-run -e 's/([1-9]{1})(?:\.[0])/$1/gi'
# replace hyphens (-) with underscores (_)
rename --dry-run 's/(-)/_/g' *
# replace 'c++' with 'cpp'
rename --dry-run 's/(c\+\+)/cpp/gi' *
# replace 'c#' with 'csharp'
rename --dry-run 's/(c#)/csharp/gi' *
# Remove brackets
rename --dry-run -f -S '[' '' -S ']' '' *
# replace '_s_' with 's_'
rename --dry-run -f -S '_s_' 's_' *
# replace '._.' with '_' (-X/--keep-extension)
rename --dry-run -X -S '._.' '' *
# replace '._' with '_' (-X/--keep-extension)
rename --dry-run -S '._' '_' -X *
# replace dot char with underscore (-X/--keep-extension)
rename --dry-run -X -S '.' '_' *
# replace dot char with space (-X/--keep-extension)
rename --dry-run -X -S '.' ' ' -X *
# replace double underscores with single
rename --dry-run 's/_-_/_/g' *
# Remove 'the last dot in the entire file/dir name'
rename --dry-run -e 's/\.$//' *
# Remove `-ebook` at the end of the dir/file
rename --dry-run -e 's/-ebook$//' *
# Remove opening and closing parenthesis `()`
rename --dry-run -e 's/\(//gx' *
rename --dry-run -e 's/\)//gx' *
# Remove opening and closing brackets `[]`
rename --dry-run -e 's/\[//gx' *
rename --dry-run -e 's/\]//gx' *
# Remove brackets "[]", exlamation points "!" and hash marks "#":
rename --dry-run -e 's/[\[\]!#]//g' *
# Replace duplicate spaces, with one space:
rename --dry-run -e 's/\s\s+/ /g' *
# Remove trailing spaces before the file extension:
rename --dry-run -e 's/\s+(\.[^.]+)$/$1/g' *
# Convert file extensions to lowercase:
rename --dry-run -f -e 's/\.([^.]*$)/.\L$1/' *
# Capitalize separate words (-X keep extension, -f force):
rename --dry-run -f -X --camelcase *
# Capitalize all characters in the file name except the file extension (-X/--keep-extension):
rename --dry-run -f -X -C *
# Rename a TV series of files, according to a season:
rename --dry-run --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 --dry-run --mkpath --counter-format 01 --keep-extension -e '$_ = "season6/S06E$N"' ./*.avi
# To rename all files (recursively) to lowercase:
find . -type f -print0 | xargs -0 rename --dry-run -f -c
# To rename all directories (recursively) to lowercase:
find . -type d -print0 | xargs -0 rename --dry-run -f -c
# To suffix all PDF files with "_cheatsheet" (e.g.: protocols_cheatsheet.pdf):
rename --dry-run --keep-extension -e '$_ = "$_\_cheatsheet"' ./*.pdf