How to rename a file in Ubuntu through terminal. Rename file via command line in Linux. Use “mv” terminal command to rename file in Ubuntu (command line).
How To Rename a File in Ubuntu
We all know how to rename a file GUI way, but for many renaming a file using Terminal commands in Ubuntu is quite confusing for others. But surprisingly, renaming a files in Ubuntu Linux, via command line is quite easy.
In Linux, renaming a file is essentially the same as moving a file from one destination to other. This is because same mv command on used to move and rename a file in Ubuntu Linux. In Linux, renaming a file is moving the name of the file.
mv Command
mv command moves or renames files (or directories). mv command is used in the following formats:
mv [OPTION]… [-T] SOURCE DEST
mv [OPTION]… SOURCE… DIRECTORY
mv [OPTION]… -t DIRECTORY SOURCE…
To rename a file in Ubuntu through Terminal, use the following command syntax:
mv Source-File ToRename-File
For example, in the following example (screenshot) we will use mv command to rename an image file named Tux-Icon.png to Pingu.png. So we will use the following command syntax:
mv Tux-Icon.png Pingu.png
Please Note:
- If two file names are given, ‘mv’ moves the first file to the second.
- If the ‘–target-directory’ (‘-t’) option is given, or failing that if the last file is a directory and the ‘–no-target-directory’ (‘-T’) option is not given, ‘mv’ moves each SOURCE file to the specified directory, using the SOURCEs’ names.
mv command can move any type of file from one file system to another. Prior to version ‘4.0’ of the fileutils, ‘mv’ could move only regular files between file systems. For example, now ‘mv’ can move an entire directory hierarchy including special device files from one partition to
another.