The basics of copying files and whole directories on Linux.
Copying files on a Linux OS can be done with cp this is obviously short for “copy”.
The syntax for cp is the source first and destination second
[source] [destination]
Copying just one file into a directory:
cp image.jpg /data/photos/
Copying two or more files into a directory:
cp image.jpg another.jpg /data/photos/
Use -p to keep file permissions and timestamps on the copied files
cp -p image.jpg /data/photos/
With cp the flag -r means recursive, to copy a whole directory into another:
cp -r /data/photos /backups/photos
This will copy the contents of the /data/photos folder into /backups/photos
To not overwrite the file if it exists use -n which is no clobber:
cp -r -n /data/photos /backups/photos
Getting a visual output from the cp task is done with the -v flag
cp -v image.jpg /data/photos/
Will output
'image.jpg' -> '/data/photos/image.jpg'
A drained and empty Kennington reservoir images from a drone in early July 2024. The…
Merrimu Reservoir from drone. Click images to view larger.
Some early September spring shots from a bushwalk, It is still too early for wildflowers.
I recently needed to clone over a smaller NVMe to a 2TB SK Hynix Platinum…
If you ever needed a simple solution in Laravel to delete an entire directory and…
How to enforce only one user to register or be registered in a Laravel web…