The cp
command in Bash is used to repeat recordsdata and directories from one location to a different.
Copy Command Syntax and Rationalization
The essential syntax of the cp
command is:
cp [OPTION]... SOURCE... DESTINATION
- SOURCE: The file or listing you need to copy.
- DESTINATION: The situation the place you need to place the copied file or listing.
- OPTION: Non-obligatory flags that modify the conduct of the
cp
command.
Generally used choices embrace:
-r
or-R
: Recursively copy directories and their contents.-i
: Immediate earlier than overwriting an present file.-u
: Copy solely when the SOURCE file is newer than the DESTINATION file or when the DESTINATION file is lacking.-v
: Verbose mode, which exhibits the recordsdata being copied.-T
: Deal with the vacation spot as a standard file. That is helpful whenever you don’t need to create a brand new listing on the vacation spot.-f
: Pressure the copy operation by eradicating the vacation spot file if it can’t be opened.
Copying Recordsdata Instance
To repeat a file from one location to a different, use the cp
command with the supply file path and the vacation spot path.
cp /path/to/supply/file.txt /path/to/vacation spot/
Instance:
cp ~/Paperwork/report.txt ~/Backup/
This command copies the report.txt
file from the Paperwork
listing to the Backup
listing.
Copying a File with a Totally different Identify
You possibly can copy a file and provides it a distinct identify within the vacation spot listing.
cp /path/to/supply/file.txt /path/to/vacation spot/newfile.txt
Instance:
cp ~/Paperwork/report.txt ~/Backup/report_backup.txt
This command copies the report.txt
file to the Backup
listing and renames it to report_backup.txt
.