Difference between mv and cp?

The mv and cp commands in Linux are used for file operations, but they serve different purposes:

mv (Move)

  • Function: Moves files or directories from one location to another.
  • Behavior: If the destination is on the same filesystem, it simply changes the file's location. If it's on a different filesystem, it copies the file and then deletes the original.
  • Usage: It can also be used to rename files or directories.
  • Example:
    mv source_file.txt /path/to/destination/

cp (Copy)

  • Function: Copies files or directories from one location to another.
  • Behavior: Creates a duplicate of the source file or directory at the destination. The original remains unchanged.
  • Usage: You can use options like -r for recursive copying of directories.
  • Example:
    cp source_file.txt /path/to/destination/

Summary

  • Use mv to move or rename files/directories.
  • Use cp to create copies of files/directories.

0 Comments

no data
Be the first to share your comment!