Copying files and directories in linux / Unix
In this post i am going to explain, How does files & directories are copied in linux using cp command.
#cp <Options> file destination
If you want to copy multiple files to a folder
#cp <Options> file1 file2 destination
Few interesting things to be known about cp command:
1. If the destination is a directory, the copy is placed there.
2. If the destination is a file, the copy overwrites the destination.
3. If the destination does not exist, the copy is renamed.
Most frequently used options with explanation:
-R : Copy files recursively.
-p : Preserver mode, ownership and timestamps.
-a – R+p : It do both recursive, mode, ownership and timestamps.
-i : Interactive, It prompts before over writing a file.
-f : Fore copy a file
To copy single file
#cp /etc/passwd /root/Desktop/
To copy multiple file
#cp /etc/passwd /etc/shadow /root/Desktop/
To copy a entire folder
#cp -R /tmp /root/Desktop