How to move files/folders from one location to other in linux?

Moving files/folders from one location to other location in linux systems is similar to windows systems but using mv(move) command, you can rename the files/folders in linux systems.

The syntax for mv command:

mv <options if required> <source file/folder name> <destination file/folder name>

Below are the options which can be used along with mv command.

Option

Description

-f, –force

Do not prompt before overwriting if same file/folder name exists in destination.
-i, –interactive

Prompt before overwrite if same file/folder name exists in destination.

-u, –update Move only when the SOURCE file is newer than the destination file or when the destination file is missing.

-v, –verbose

Explain what is being done.

 

Prerequisites:

1. Read/Write access to source file or folder which you are trying to move and Read/Write in destination path.

Here are the examples using mv command.

1. To move a file from present working directory/folder to other directory/folder,

mv <filename> <directory_name/>

mv file1 dir1/

The above operation will succeed if you have read/write access to the file which you are moving and read/write access to the destination folder. In the above example, the file1 and dir1 folder is under /home/user1 folder with read/write access to the user.

Note : You should specify absolute path for source and destination if you are trying to move or rename the files/folders from other working folder.

2. To rename the file/folder name,

mv <present_file/folder name> <new_file/folder name>

mv file 2 file22

After moving files from one folder to other folder without renaming the file/folder name, the change time of the file/folder will be updated as below.

Blue highlighted shows the present time in the system.

Yellow highlighted shows the change time before moving the file into dir1 folder.

Red highlighted shows the changed time after moving the file into dir1 folder.

While renaming the file/folder name, the change time of the file/folder name will be update as below.

Blue highlighted shows the present time in the system.

Yellow highlighted shows the change time before renaming the file88.

Red highlighted shows the changed time after renaming the file into file88.

The Access time of the file is updated after viewing the file content as below.

Yellow highlighted shows the access time before viewing the file88.

Red highlighted shows the changed time after viewing the file into file88.

Similarly, The access time of the folder/directory is update after viewing or listing the directory contents as below.

Yellow highlighted shows the access time before viewing the contents of dir1 folder.

Red highlighted shows the changed time after viewing the contents of dir1 folder.

SUMMARY :
  1. The Access time of file/folder will be updated once the file/folder contents are viewed.
  2. The Modify time of file/folder will be updated once the file/folder contents are modified.
  3. The Change time of file/folder will be updated once the file/folder contents are renamed.

To know how to copy the files/folders from one location to other, Click Here!!

How do you feel about this post or want to suggest a new post? Drop your comments below..