Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

linux
file handling

What are cp and mv in Linux?

Muhammad Muzammil

When working in Linux, it is common to navigate across multiple directories and perform various tasks using the terminal.

As a result, it can be beneficial to copy and move certain files and folders from one directory to another.


Note that moving a file/folder will delete it from its source while copying it will not.

Copying/Moving from non-current directory to the current directory

To copy/move a file or folder in another directory to your current working directory, you can use the following terminal commands:

Copy


cp path_source .

Move


mv path_source .

path_source is the path to the source directory, and . represents the current working directory.

Copying/Moving from the current directory to a non-current directory

To copy/move a file in the present working directory to another directory in your file system, you can use the following commands:

Copy


cp name destination_path

Move


mv name destination_path

Where name is the name of the file/folder to move/copy, and destination_path is the destination directory.

Copying/Moving from a non-current working directory to a non-current working directory

To copy/move a file in a non-current working directory to another non-current working directory in your file system, you can use the following commands:

Copy


cp source_path destination_path

Move


mv source_path destination_path

Where source_path is the file’s path to be moved from its current location to a different location, destination_path.

RELATED TAGS

linux
file handling
RELATED COURSES

View all Courses

Keep Exploring