Difference Between Copying and Moving

The main difference between copying and moving is that the copying makes a duplicate of a file or directory in another location without affecting the original content while moving transfers the original file or directory to another location. 

While working with computers, sometimes it is necessary to make duplicates of the same file or directories. Copying is a solution to this. It does not affect the original content. Instead, it makes a similar copy of the original to the new location. Moving, on the other hand, follows a different process. It transfers a file or a directory to another location. The original content is deleted, and a new one is available in the new location. This articles specifically discusses copying and moving in Linux.

Key Areas Covered

1. What is Copying
      – Definition, Functionality
2. What is Moving
     – Definition, Functionality
3. Difference Between Copying and Moving
     – Comparison of Key Differences

Key Terms

Copying, Command cp, Command mv, Moving, Linux

Difference Between Copying and Moving - Comparison Summary

What is Copying

Copying makes a duplicate of a file or directory into a new location. In Linux, the “cp” command allows the user to copy a file or a directory.

The following command creates a copy of file1 and names it as file2. If the file2 already exists, it will be overridden with the new content.

cp file1.txt  file2.txt.

Moreover, it is possible to copy a file to a new location by specifying the destination location.  The following command copies a file to the new directory.

cp file1.txt  /home/user1/Desktop/dir2

The following command copies all the content in the directory dir1 to the destination directory.

cp –r  dir1  /home/user1/Desktop/dir2

When copying files or directories, the original content will not be affected. Therefore, the user can see the original file or the directory at the initial location.

What is Moving

Moving transfers the original files or directories from one location to another. It deletes the content from the first location and creates content in a new location.

Difference Between Copying and Moving

Figure 1: Files and Directories

In Linux, the mv command is used to move a file or a directory to a new location.

mv doc1 doc2

In the above example, the doc1 file moves to doc2 in the same directory. Now there is no doc1. There is only doc2.

The following command sends the doc1 in the current directory to another directory. It will transfer the doc1 file from the current directory to the specified directory.

mv doc1 /home/user1/desktop/dir2

Similarly, it is possible to move a directory. The following command will transfer the dir1 to dir2 in the same directory. Now there is no dir1, and there is only dir2.

mv dir1 dir2

Below command will transfer the dir1 to the specified directory. Now there is no directory named dir1 in the current directory. It is in the new directory.

mv dir1 /home/user1/desktop/dir2

When moving the files or directories to the same directory, only the content will be replaced by a new name. Therefore, it is not exactly moving. It is renaming.

Difference Between Copying and Moving

Definition

Copying is a command that allows creating a similar file or a directory in a new location. Moving is a command that allows relocating the original file or a directory in a new location.

Main Functionality

The copying function makes a duplicate of a file or a directory in another location. Moving will transfer the original file or a directory to another location.

Original Content

Copying will not affect the original content, but moving will delete the original content.

Conclusion

The difference between copying and moving is that the copying command makes a duplicate of a file or directory to another location without affecting the original content while the moving command transfers the original file or directory to another location. 

Reference:

1. “Linux Cp | Linux Copy File and Directory” Javatpoint.” Available here.
2. “Linux Mv | Linux Move File” Javatpoint, Available here.

Image Courtesy:

1. “Files11 directory hierarchy” By en:User:Kate, User:Stannered – en:Image:Files11 directory hierarchy.png (Public Domain) via Commons Wikimedia

About the Author: Lithmee

Lithmee holds a Bachelor of Science degree in Computer Systems Engineering and is reading for her Master’s degree in Computer Science. She is passionate about sharing her knowldge in the areas of programming, data science, and computer systems.

Leave a Reply