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.
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.