This command is used to copy one or more files from source path to destination path.
1 |
cp –[OPTION] [source] [destination] |
1 |
# cp originalfile newfile |
Explanation:
1 |
#cp originalfile /home/root |
Or
1 |
#cp originalfile /home/root/. |
Both syntax are same. The forward slash-dot (/.) is implied in second command (the dot is very special in every Linux directory which means “this directory”).
Suppose originalfile is at following path: /home/root/folder1/contentfile. Then, above syntax will be written as:
1 |
# cp /home/root/folder1/contentfile/originalfile /home/root |
1 |
# cp originalfile /home/root/testFile |
1 |
# cp /home/root/testing* /home/ram |
1 |
# cp /home/root /home/ram |
1 |
# cp –v originalfile /home/root |
If destination folder already have a file and we know that by using cp command, it will overwrite the same in destination directory. So, we use – backup option , cp command will make a backup of each existing file.
1 |
# cp –backup=simple –v *.txt /home/root |
–backup=simple option will create a backup file which will be marked by a tilde sign(~) at the end of file. —backup option has following control options:
Few questions with their answers are present in assignment section for this command.
Leave a Reply