How do I rename a file in bash under UNIX / OS X / Linux / BSD operating systems?
The mv command rename SOURCE file to DESTINATION file using the following syntax:
mv oldname newname mv source dest mv olddir newdi
Task: Rename A File Called /tmp/foo To /tmp/bar
Type the following command (open terminal and issue the following commands):
# create /tmp/foo touch /tmp/foo ls -l /tmp/foo mv /tmp/foo /tmp/bar ls -l /tmp/bar ls -l /tmp/foo
Task: Rename A Directory Called offfer To offers
Type the following command:
mv offfer offersTask: Prompt Before Overwrite
The -i option is interactively file processing option. You get an error message before moving a file that would overwrite an existing file. If the response from the user begins with the character y or Y, the move / rename is attempted.
touch /tmp/test mv -i /tmp/test /tmp/ba
Sample outputs:
mv: overwrite `/tmp/bar'? y
The -u Option
The -u option move only when the SOURCE file is newer than the destination file or when the destination file is missing:
mv -u data.txt /mnt/floppy/backup.txtThe -v Option
The -v option explain what is being done:
mv -v /tmp/bar /tmp/output.txtSample outputs:
`/tmp/bar' -> `/tmp/output.txt'
Task: Rename multiple files
Use rename command renames multiple files. For example rename all *.perl file as *.pl, enter:
rename .perl .pl *.perl
See howto rename multiple files at a shell prompt for further details.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 1 comment… read it below or add one }
typo here:
ename .perl .pl *.perl
instead of
rename