Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
NAME
cp - copy files and directories

SYNOPSIS
cp [OPTION...] [-T] SOURCE DESTINATION
cp [OPTION...] SOURCE... DIRECTORY

DESCRIPTION
Copy SOURCE to DESTINATION, or multiple SOURCE(s) to DIRECTORY

OPTIONS
-i
Prompt before overwriting.

-n
Do not overwrite an existing file.

-p
Preserve the last-modified time of the file.

-r
Copy directories recursively.

-T
Treat DESTINATION as a normal file.

-u
Copy only when the source file is newer than the destination file, or when the destination file is missing.

EXAMPLES
To copy a file
Code Block
cp /home/tariq/foo.sql /home/tariq/sahil/foo.sql

To copy a directory
Code Block
cp /home/tariq/foo /home/tariq/sahil/

...

     
To recursively copy subdirectories, use the -r option:
Code Block
cp -r /home/tariq/foo /home/tariq/sahil/

To preserve the last modified time of file, use the -p option:
Code Block
cp -p /home/tariq/foo.sql /home/tariq/sahil/foo.sql

To prompt before overwriting an existing file using cp command:
Code Block
cp -i /home/tariq/foo.sql /home/tariq/sahil/foo.sql

To copy only when the source file is newer than the destination file, use the -u option
Code Block
cp -u /home/tariq/foo.sql /home/tariq/sahil/foo.sql

NOTES
If both -n and -i are specified, -n will take precedence.

If both -n and -u are specified, -n will take precedence.
 
SEE ALSO
rm