The cp
command in Bash is used to copy files and directories from one location to another. It allows users to duplicate files, preserving their contents and attributes, and can also be used to create backups.
The basic syntax of the cp
command is as follows:
cp [options] [source] [destination]
-r
or --recursive
: Copy directories recursively.-i
or --interactive
: Prompt before overwriting files.-u
or --update
: Copy only when the source file is newer than the destination file or when the destination file is missing.-v
or --verbose
: Show the files being copied.-a
or --archive
: Preserve the original file attributes (like timestamps and permissions) while copying.cp file.txt /path/to/destination/
cp -r /path/to/source_directory /path/to/destination_directory/
cp -i file.txt /path/to/destination/
cp -u file.txt /path/to/destination/
cp -v file.txt /path/to/destination/
-i
option if you’re unsure whether the destination file exists to avoid accidental overwrites.-v
option to monitor the progress of the operation.-a
option when you want to maintain the original file attributes, especially when backing up files.