Linux cp command

13.02.2023
21:17

While working in the terminal, it is often necessary to copy files. The cp Linux command is most often used for this purpose. It comes by default in all distributions and can copy files and folders and save their attributes in Linux file systems.

About the cp command

The "cp" command in Linux is used to copy files and directories. The syntax of the command is as follows:

cp [options] <source file/directory> <target file/directory>

For example, the following command can be used to copy thefile "file.txt" to the directory"/home/user/documents":

cp file.txt /home/user/documents/

If you want to copy all files from directory"dir1" to directory"dir2", you can use the following command:

cp -r dir1/* dir2/

Some of the most commonly used options forthe "cp" command are:

-r or --recursive: copy directories recursively, including all files and subdirectories;

-v or --verbose: output information about the copying process;

-i or --interactive: prompt for confirmation before copying files;

-u or --update: copy only files that are newer than existing files in the target directory;

-p or --preserve: preserve file attributes (owner, permissions, timestamps, etc.).

More information about the"cp" command and its options can be obtained by running the"man cp" command.

15% discount on new VPS
Hurry up to order a server in any location
Choose a VPS

Other articles

13.02.2023
25 453
Knowledge base / Instructions
How to make a frame in LibreOffice
13.02.2023
17 651
Knowledge base / Instructions
Recording video from the screen in VLC in Linux
13.02.2023
8 350
Knowledge base / Instructions
Instructions for installing Samba in Ubuntu, Debian and CentOS