What is cp command in Linux?
At its core, cp stands for copy. It is a command-line utility that allows users to make copies of files and directories. Wehther you are duplicating important documents, backing up crucial data, or simply organizing your files. Let’s explore its functionality and various options.
Understanding the Basics
Executing the cp
command without any options simply copies a file or directory from one location to another.
cp source_file destination_file
Options
-r
The recursive option allows copying entire directories and their contents recursively.
cp -r source_file destination_file
-i
The interactive option prompts the user for confirmation before overwriting existing files.
cp -i source_file destination_file
-v
The verbose option displays detailed information about each file being copied, providing feedback on the operation’s progress.
cp -v source_file destination_file
-u
The update option copies only when the source file is newer than the destination file or when the destination file is missing.
cp -u source_file destination_file
-p
The preserve option retains the original file attributes, such as permissions, timestamps, and ownership, when copying files.
cp -p source_file destination_file
-l
The link option creates hard links instead of copying the file itself, saving disk space by referencing the same data.
cp -l source_file destination_file
-s
The symbolic link option creates symbolic links (symlinks) instead of copying the file, providing a lightweight reference to the original file.
cp -s source_file destination_file
-b
The backup option creates backups of existing destination files before overwriting them, helping prevent accidental data loss.
cp -b source_file destination_file
Additionally, to delve even deeper into the functionality of each option, you can explore further by using the respective command followed by:
cp --help
# or
# consulting the manual pages
man cp
These commands provide comprehensive documentation and explanations for each option
Thank you!
Thank you for your time and for reading this!