Living in the Shell #11; cp (Copy Files/Directories)
Babak K. Shandiz
Posted on December 10, 2021
cp
š
Creates copies of files and directories.
ā ļø Default behavior is to overwrite destination files.
Copy single file
cp ~/.bashrc ~/.bashrc-copy
Copy multiple files into a new directory -t
cd ~ && cp .bashrc .zshrc target-dir
cd ~ && cp -t target-dir .bashrc .zshrc
Both create
target-dir
directory and copy.bashrc
and.zshrc
into it.
Copy by wildcard selection -t
cd ~ && cp -t target-dir *.zip *.txt
Copies all
.zip
and.txt
files totarget-dir
directory.
Copy a directory -r
cp -r ~/.config ~/.config-copy
Update only newer files -u
cp -ru ~/.config ~/.config-last-backup
This just copies files that modified after the last copy.
Create backup for existing destination files -b
cp -rb ~/.config ~/.config-last-backup
Set to ask for overwriting -i
cp -ri ~/.config ~/.config-last-backup
Set to keep existing files (no overwrite) -n
cp -rn ~/.config ~/.config-last-backup
š šŖ š
š©
Babak K. Shandiz
Posted on December 10, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.