cp (BSD) Cheatsheet #
The cp
command is used to copy files and directories in Unix-like operating systems.
Basic Commands #
Command/Option | Example | Description |
---|---|---|
cp file1 file2 | cp example.txt backup.txt | Copy example.txt to backup.txt |
cp -R dir1 dir2 | cp -R mydir backupdir | Copy directory mydir to backupdir |
cp -i file1 file2 | cp -i example.txt backup.txt | Prompt before overwriting files |
cp -u file1 file2 | cp -u example.txt backup.txt | Copy only when the source file is newer than the destination file |
Advanced Options #
Command/Option | Example | Description |
---|---|---|
cp -p file1 file2 | cp -p example.txt backup.txt | Preserve file attributes (timestamps, ownership) |
cp -L file1 file2 | cp -L example.txt linkfile | Follow symbolic links and copy the target file |
cp -v file1 file2 | cp -v example.txt backup.txt | Verbose mode, show files as they are copied |
This cheatsheet provides key BSD cp
options for copying files and directories.