Chapter 2. Linux Key Commands

Mv (Move File and Directory)

Mv (Move File and Directory)
Tag:

The mv (MoVe) command is used to move a file or directory to another path.

Move a file or directory

There are two key arguments in the mv command.

  • 1st argument: file or directory path
  • 2nd argument: destination directory path (existing directory path)

For example, if you want to move file_a under your working directory to dir_a under your working directory, run the command below.

Command Line - INPUT
mv file_a dir_a

Change the file or directory name

You can also use the mv command, to change an existing file or directory name to a new name. The syntax structure is the same as the one to move a file or directory. The key difference is that the 2nd argument should be a new name that you want to use for the file or directory.

For example, if you run the same command as in the previous example when there is no dir_a directory, the file name of file_a becomes dir_a.

Moving a file or changing a file name

Depending on the directory situation, the same command can create different results.

When there is no directory whose name is the same as the intended new file name, the mv command changes the file name as illustrated below.

mv-Move-File-and-Directory

When there is a directory whose name is the same as the intended new file name, the mv command moves the file to the directory as illustrated below.

mv-Move-File-and-Directory

The mv (MoVe) command is used to move a file or directory to another path.

Move a file or directory

There are two key arguments in the mv command.

  • 1st argument: file or directory path
  • 2nd argument: destination directory path (existing directory path)

For example, if you want to move file_a under your working directory to dir_a under your working directory, run the command below.

Command Line - INPUT
mv file_a dir_a

Change the file or directory name

You can also use the mv command, to change an existing file or directory name to a new name. The syntax structure is the same as the one to move a file or directory. The key difference is that the 2nd argument should be a new name that you want to use for the file or directory.

For example, if you run the same command as in the previous example when there is no dir_a directory, the file name of file_a becomes dir_a.

Moving a file or changing a file name

Depending on the directory situation, the same command can create different results.

When there is no directory whose name is the same as the intended new file name, the mv command changes the file name as illustrated below.

mv-Move-File-and-Directory

When there is a directory whose name is the same as the intended new file name, the mv command moves the file to the directory as illustrated below.

mv-Move-File-and-Directory

Tag: