14. cp_command - muneeb-mbytes/linux_course GitHub Wiki

cp_command

The below figure represents the cp command variations.

cp command variations

                                   Figure.1.Representation of cp command variation

copy command cheat sheet

Sr No. copy command with different options description
1 cp [source file] [destination file] Copy the source file contents to destination file
2 cp -r [source file] [destination file] Copies all files of the source files to the destination files
3 cp --help List all copy command options
               Tabular column.1. copy command cheat sheet

cp

cp command is used to copy the source file contents to destination file. cp command copies the files or directories. It creates an exact image of a file on a disk with different file name.

syntax: cp [source file] [destination file]

Example: cp file1.txt file2.txt

The below figure shows the output of cp file1.txt file2.txt, where the file1 content is copied to file2.

cp pic

                                      Figure.1. cp command output

The below gif will show how copy command works in linux and copied happens in destination directory from source directory.

copy_command

                                       GIF.1. cp command gif

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/cp_commands/copy.csh


cp -r

cp -r command copies all files of the source files to the destination files, creating any files when needed. 'r'used to indicate the recursive copying of directories.

syntax: cp -r [source file] [destination file]

Example: cp -r [source file] [destination file]

Note:- If the Destination file doesn’t exist, cp creates it and copies content of source file recursively. If the destination file exists then copy the contents of source file to destination file.

The below figure shows the recursive copy operation and it's output. cp-r

                                       Figure.2. cp -r command output

The below gif shows the how cp -r command copies the contents from source directory to destination directory. cp-r

                                         GIF.2. cp -r command gif 

Link to GitHub lab:https://github.com/muneeb-mbytes/linux_course/blob/b7_team_kachori/cp_commands/cp-r.csh


cp --help

To list all cp command options, type cp --help. The system lists all available options.


To learn find command: https://github.com/muneeb-mbytes/linux_course/wiki/15.-find-command