You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

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

cp /home/tariq/foo.sql /home/tariq/sahil/foo.sql

To copy a directory

cp /home/tariq/foo /home/tariq/sahil/

 To recursively copy subdirectories, use the -r option:

cp -r /home/tariq/foo /home/tariq/sahil/

To preserve the last modified time of file, use the -p option:

cp -p /home/tariq/foo.sql /home/tariq/sahil/foo.sql

To prompt before overwriting an existing file using cp command:

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

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

  • No labels