What’s the standard way to rename files from the command line?
Asked by
43 lunch breaks
I'm used to browsing files with nnn, but I'm tired of relying on it whenever I need to rename something. What commands or tools do you usually use to rename a single file or rename multiple files on Linux?
Answers
For a single file, the usual command is simply `mv old-name new-name`. Despite the name, `mv` works for both moving and renaming files.
Reply to this answer
For batch renaming, many Linux systems provide a `rename` command, which can apply a pattern or substitution across multiple filenames. The exact syntax can vary between implementations, so check `rename --help` or its manual page first.
Reply to this answer
The giant Bash-script approach is technically entertaining, but it’s wildly unnecessary for a rename. Plain `mv` is the standard tool and is already included on essentially every Linux system.
Reply to this answer
If you want protection against accidentally overwriting an existing destination, use `mv -i old-name new-name`. It will ask for confirmation before replacing anything.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions