Copying: cp
¶
Option Overview¶
Option |
Description |
---|---|
|
Recursive (to copy entire directories) |
|
Preserve timestamps and permissions |
|
Verbose (print progress as you go; most commonly used together
with |
|
Don’t let me shoot myself in the foot: prompt before overwrite |
Creating backup copy of, say, .bashrc
in the home directory¶
$ cp .bashrc .bashrc.save
Danger
cp
(and no other command like it) doesn’t keep you from shooting yourself in the foot
$ cp .bashrc .bashrc.save
Solution: -i
$ cp -i .bashrc .bashrc.save
cp: overwrite '.bashrc.save'? y
Similar: copy a file into a different directory, under a different name¶
$ cp .bashrc /tmp/jfaschs-bashrc
Similar: copy a file into a different directory, keeping its name¶
$ cp .bashrc /tmp
Copy multiple files into a directory¶
(The target directory must exist!)
$ cp ~/Downloads/IMG_*.jpg ~/Pictures/Fotos\ für\ Bilder/
Copying a directory, together with its contents ⟶ recursive copy¶
$ cp -r .thunderbird /var/backup/jfasch/thunderbird-backup-2022-03-10