Linux Commands Helper
💬 Your AI-powered Linux assistant
cp Command - Copy Files or Directories
The cp command is used to copy files or directories from one location to another.
Syntax
cp [options] source target
Common Options
-i
: Prompt before overwrite.-r
: Copy directories recursively.-p
: Preserve file attributes.-u
: Copy only when the source is newer or the target does not exist.-v
: Show files as they are copied.
Examples
cp file1.txt /home/user/docs/
Copy file1.txt to the /home/user/docs/ directory.
cp -r dir1 /home/user/backup/
Recursively copy dir1 to /home/user/backup/.
cp -i file1.txt file2.txt
Copy file1.txt to file2.txt with overwrite confirmation.
Notes
- The cp command does not change the original file, it only creates a copy.
- Be careful when copying over existing files to avoid unintentional data loss.