mv old.txt new.txt # rename
mv -i file dir/ # prompt before overwriting
mv -n file dir/ # never overwrite
mv -v *.log /var/archive/ # verbose
mv -t /dest file1 file2 # target directory first: pairs well with xargs
Names that fight back¶
# A name that starts with a dash is parsed as an option: use -- or a path prefix
mv -- "-Cx6Zh_qoDc.webm" "Concert Live - Welcome.webm"
mv ./-Cx6Zh_qoDc.webm "Concert Live - Welcome.webm"
# A trailing question mark (or other shell-special character): escape or quote it
mv 'Young and Innocent (1937).avi?' 'Young and Innocent (1937).avi'
Tab completion helps with odd names. If a name contains a newline (for example from pasting a multi-line string into mkdir), quote it over several lines exactly as it appears, or use find . -maxdepth 1 -name 'Intro*' -exec rm -rf {} +. Reverse the mistake by mimicking how you created it.
Bulk renaming¶
Renaming many files at once is covered in rename: shell loops with parameter expansion, Perl rename, and util-linux rename.