Move and rename in Linux with mv command

by Daniel Pham
Published: Updated:
This entry is part 2 of 4 in the series Linux commands: Part 4 - Manipulating files and directories

In Linux, to perform the move or rename of a file or directory, we use the mv command. This command performs one of the two features mentioned, depending on usage. In either case, the original filename no longer exists after the operation. mv is used in much the same way as cp command.

Use mv command

To move or rename file or directory “item1” to “item2”.

mv item1 item2
Move and rename in Linux with mv command
mv command

To move one or more items from one directory to another.

mv item... directory

mv command useful options

mv command have many options as the same as cp command:

-bmake a backup of each existing destination file but does not accept an argument
-fdo not prompt before overwriting
-iBefore overwriting an existing file, prompt the user for
confirmation. If this option is not specified, mv will
silently overwrite files.
-uWhen moving files from one directory to another, only
move files that either don’t exist, or are newer than the
existing corresponding files in the destination
-vDisplay informative messages as the move is

To display all options of mv command, execute command below:

mv --help

Some examples of mv command

Read moreListing the contents of a directory

Rename file1 to file2.

mv file1 file2
Move and rename in Linux with mv command
Use mv command to rename file1 to file2

Move file1 and file2 to a directory, you can use for directory as the same way.

mv file1 file2 dir/
Move and rename in Linux with mv command
Use mv command to move files to a directory


This command works very similar to the cp command. The use of the this command should be very careful because it can delete the target file or directory during the use of the command.

(This is an article from my old blog that has been inactive for a long time, I don’t want to throw it away so I will keep it and hope it helps someone).

0 0 votes
Article Rating
Series Navigation«« Previous part: Copy files and directories with “cp” commandNext part: Create directories with mkdir command »»

You may also like

Notify of
Inline Feedbacks
View all comments

DevOps Lite is a personal blog specializing in technology with main topics about DevOps, DevSecOps, SRE and System Administrator. Articles are shared for free and contributed to the community.



Subscribe my Newsletter for new blog posts. Stay updated from your inbox!

© 2021-2024 – All rights reserved.

Please write sources “” when using articles from this website.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Would love your thoughts, please comment.x

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.