rename: Ultimate Guide to Batch File Renaming in Linux
Unlock the power of batch file renaming in Linux with the rename utility. Explore a comprehensive collection of commands for renaming
files and directories. Learn how to remove parentheses, replace spaces with underscores, convert case, change extensions, add prefixes, and much more.
Remove all Parentheses from file/folder names
rename '(' '' *
rename ')' '' *
Rename all spaces to underscore
for file in *' '*; do
mv -- "$file" "${file// /_}";
done
Rename all files with spaces to underscore
for file in *; do
mv -- "$file" "${file// /_}";
done
Rename uppercase to lowercase
for i in *; do
mv $i `echo $i | tr 'A-Z' 'a-z'`;
done
for i in $( ls | grep [A-Z] ); do
mv -i $i `echo $i | tr 'A-Z' 'a-z'`;
done
Rename all uppercase to lowercase
Remove .sh file extension for files in the current directory
Remove all spaces from all files in the current folder
Rename multiple files from .php to .html
rename s/ .php/ .html/ *.html
Replace spaces in filenames with underscores
Renames all files in the current directory to contain no space characters
Batch file suffix renaming
Rename all files containing 'foo' with 'bar'
Batch rename extension of all files in a folder, from .txt to .md
Rename all files containing 'foo' with 'bar'
Batch rename extension of all files in a folder, from .txt to .md
Convert single digits to double digits
rename 's/\d+/sprintf("%02d",$&)/e' $@
Replace spaces in filenames
Rename multiple files in one go
rename 's/.xls/.ods/g' *.xls
Convert filenames in the current directory to lowercase
Title Case Files
rename 's/\b((?!(a|of|that|to)\b)[a-z]+)/\u$1/g' *
Convert uppercase files to lowercase
Change the extension of a filename
Replace strings in filenames
rename 's/foo/bar/g' foobar
Clean up poorly named TV shows
rename -v 's/.*[s,S](\d{2}).*[e,E](\d{2}).*\.avi/SHOWNAME\ S$1E$2.avi/' poorly.named.file.s01e01.avi
Yet Another Rename (bash function)
rename(){
txtToReplace=${1} ;
replacementTxt=${2} ;
shift 2 ;
files=${@} ;
for file in $files ; do
mv ${file} ${file/${txtToReplace}/${replacementTxt}} ;
done
}
Convert spaces in filenames to underscores
Rename all .jpeg and .JPG files to have .jpg extension
rename 's/\.jpe?g$/.jpg/i' *
Replace spaces in a filename with hyphens
Replace spaces in filenames with underscores
Copy/move a bunch of files to dot files and back
Rename all .jpeg and .JPG files to .jpg
rename 's/\.jpeg/\.jpg/' *.jpeg; rename 's/\.JPG/\.jpg/' *.JPG
Rename files in batch
rename 's/^hospital\.php\?loc=(\d{4})$/hospital_$1/' hospital.php*
Batch rename extension of all files in a folder, from .txt to .md
rename 's/\.txt$/\.md$/i' *
Title Case Files
rename 's/(^|[\s\(\)\[\]_-])([a-z])/$1\u$2/g' *
rename 's/\b([a-z])/\u$1/g' *
Add prefix onto filenames
Tracklist replace backspace with '-'
Change file extension
rename .oldextension .newextension *.oldextension
Numeric zero padding file rename
rename 's/\d+/sprintf("%04d",$&)/e' *.jpg
Adding Prefix to File name
Adding Prefix to File name
rename 's/^/CS749__/' *.pdf
Renames multiple files that match the pattern
Space to underscore across a single directory
Replace all the spaces in all the filenames in the current directory and including directories with underscores
Adding leading zeros to a filename (1.jpg -> 001.jpg)
rename.ul "" 00 ?.jpg; rename "" 0 ??.jpg;
Replace Space In Filenames With Underscore
Rename with a regular expression and leading zeros
rename 's/result_([0-9]+)_([0-9]+)_([0-9]+)\.json\.txt/sprintf("%d%02d%02d.txt",$3,$2,$1)/ge' result_*.txt