cp Command in Linux

Posted by

Good day! Have you ever been curious about how Linux or Unix operating systems copy files? You’re in luck though, since we’re going to explore the fascinating world of the cp command today! You may easily create copies of files and directories using this strong command. So let’s get going!

What does cp command mean?

In Linux and Unix systems, the “copy” command (abbreviated “cp”) is used to make copies of files and directories. This command is flexible and can be used to copy a single file, a group of files, or even an entire directory.

Syntax and Usage

The cp command has a very basic syntax. Here is a simple illustration:

cp source_file destination_file

In this example, source_file denotes the source file and destination_file denotes the destination file’s name.

However, there’s still more! Additionally, a large number of options are supported by the cp command to expand its usefulness. Here are a few frequently chosen choices:

When you want to recursively replicate a directory’s whole contents, you use the

  • -r or –recursive option.
  • -v, often known as –verbose: Displays comprehensive information about the files being copied.
  • -i, often known as “interactive,” asks for your approval before overwriting an existing file.
  • The -p or –preserve option keeps the original file’s permissions and timestamps intact.

Examples

source_file denotes the source file and destination_file denotes the destination file’s name.

Copying a Single File:

cp file1.txt file2.txt

By using this command, a copy of file1.txt called file2.txt is created.

Multiple File Copies:

cp file1.txt file2.txt file3.txt destination_directory/

Three files (file1.txt, file2.txt, and file3.txt) are being copied to the destination_directory in this example.

Copying a Directory:

cp -r source_directory/ destination_directory/

Three files (file1.txt, file2.txt, and file3.txt) are being copied to the destination_directory in this example.

0 0 votes
Article Rating
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
trackback

[…] cp Command in Linux […]

1
0
Would love your thoughts, please comment.x
()
x