September 21, 2025
Linux Command Line

Linux Command Line

The ‘mv’ command in Linux is a powerful tool for managing and organizing files and directories. It stands for “move” and it is used to move or rename files and directories. This guide will cover when to use the ‘mv’ command, and how to use it with some examples.

When to Use ‘mv’:

  • To move a file from one directory to another
  • To rename a file
  • To rename a directory

Before we begin, it’s important to note that the ‘mv’ command can be used to move both files and directories. However, when moving a directory, all of its contents will also be moved.

Syntax of the command: The basic syntax of the ‘

mv’ command is as follows:

mv [source] [destination]

Where [source] is the file or directory that you want to move or rename, and [destination] is the new location or name for the file or directory.

Examples:

  1. Move a file from one directory to another:
mv /home/user/document.txt /home/user/documents/

This example moves the file “document.txt” from the “home/user” directory to the “home/user/documents” directory.

  1. Rename a file:
mv /home/user/document.txt /home/user/new_document.txt

This example renames the file “document.txt” to “new_document.txt” in the “home/user” directory.

  1. Rename a directory:
mv /home/user/old_directory /home/user/new_directory

This example renames the directory “old_directory” to “new_directory” in the “home/user” directory.

In conclusion, the ‘mv’ command is a versatile and useful tool for managing and organizing files and directories in Linux. With the knowledge of when and how to use it, you’ll be able to easily move and rename files and directories from the command line.

See our list of 75 Linux commands you should know about.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x
Share via
Copy link
Powered by Social Snap