Do you not like the name of any file or directory? Do you want to change it? Do you want to give new name to file or directory?
If you don’t know how to rename a file in Linux then this article is helpful for you.
When you read complete article, You will learn about move and rename files.
You must read warnings mentioned in the article. Cautions make you perfect, and save you from disaster happen by using wrong command.
- mv command in linux to rename File.
- Rename multiple files in Linux by Single Command
- Graphical Interface to rename file
mv command in linux to rename File.
mv command is most used command in Linux, mv is the short form of move.
mv command is widely used to move files and directories from one location to another location.
In other hand, mv command in Linux is also used to rename file or directory.
Basic command syntax of mv command as following:
mv [OPTION] .. [SOURCE] [DEST]
I am have created file resume.doc by mistake and I want to rename it to resume.doc in the same directory. The following syntax will be used:
vijay@Ubuntu-19:~$ mv resumex.doc resume.doc vijay@Ubuntu-19:~$
If you want two work rename file and move file to another location from the current directory then the syntax will be as follow.
vijay@Ubuntu-19:~$mv resumex.doc Documents/resume.doc vijay@Ubuntu-19:~$ls Documents/ resume.doc vijay3.doc vijay@Ubuntu-19:~$
Now, this is the another method to rename file in Linux by using mv command, If you want to rename and move file from source to destination.
For example if resumex.doc file is in /home/vijay/Videos folder and want to rename and move it to the location /home/vijay/documents.
Syntax is :
vijay@Ubuntu-19:~$ls Videos/ resumex.doc vijay@Ubuntu-19:~$mv Videos/resumex.doc Documents/resume.doc vijay@Ubuntu-19:~$ls Documents/ resume.doc vijay3.doc vijay@Ubuntu-19:~$
Rename multiple files
Linux System Administrator has lots of workload, but he remove it easily by using his talent of smart working.
For the example assume you are a system administrator get a folder consist 1000 pdf files and your boss want all files in .doc files.
What will you do now?
Assume if you rename all 1000 files ony by one, how much time will you need to rename these files.
I say “you can do it by single command” and the command name is rename. But rename does not come in Linux pre-installed.
You must install rename in Linux first. I am using Ubuntu 19.04 so You can see demo on Ubuntu.
Install rename on Ubuntu 19.04
vijay@Ubuntu-19:~$sudo apt-get install rename [sudo] password for vijay: Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: rename 0 upgraded, 1 newly installed, 0 to remove and 8 not upgraded. Need to get 16.1 kB of archives. After this operation, 48.1 kB of additional disk space will be used. Get:1 http://in.archive.ubuntu.com/ubuntu disco/universe amd64 rename all 1.10-1 [16.1 kB] Fetched 16.1 kB in 1s (11.5 kB/s) Selecting previously unselected package rename. (Reading database ... 136237 files and directories currently installed.) Preparing to unpack .../archives/rename_1.10-1_all.deb ... Unpacking rename (1.10-1) ... Setting up rename (1.10-1) ... update-alternatives: using /usr/bin/file-rename to provide /usr/bin/rename (rename) in auto mode Processing triggers for man-db (2.8.5-2) ... vijay@Ubuntu-19:~$
Now the next step rename all the files .pdf to .doc
$ rename ‘s/oldfiles/newfiles/’
$rename ‘s/\.pdf$/\.doc/’ *.pdf
vijay@Ubuntu-19:~/Documents~$ls file10.pdf file2.pdf file4.pdf file6.pdf file8.pdf file.pdf resumex.pdf file1.pdf file3.pdf file5.pdf file7.pdf file9.pdf resume.pdf vijay3.pdf vijay@Ubuntu-19:~/Documents~$rename 's/\.pdf$/\.doc/' *.pdf vijay@Ubuntu-19:~/Documents~$ls file10.doc file2.doc file4.doc file6.doc file8.doc file.doc resumex.doc file1.doc file3.doc file5.doc file7.doc file9.doc resume.doc vijay3.doc vijay@Ubuntu-19:~/Documents$
Graphical Interface to rename file
Linux is growing day by day in matter of usability. Linux has good graphic interface now.
For Example Ubuntu has awesome Graphical User Interface with lots of utilities. You can rename file like windows OS by using graphical inter face.
Follow the given steps to rename file:
Step #1 right click on the file or directory, what do you want to rename. then click on rename.
Step #2 give the newname to file or directory and click on OK
Step #3 check the result whatever you get.
When you start to work on Linux, and become good user of command line, Trust me you don’t like graphical interface any more for work purpose. off-course you will not like to see movie by command line.
So you have seen it easy to learn about “how to rename file in linux” not only this you can now rename multiple files in single command.
If you have any question write in comment or mail me at email@example.com.