Skip to content

Copying (cp)

Copy foo.txt from /path/to/source/ to /path/to/target/folder/

Terminal window
cp /path/to/source/foo.txt /path/to/target/folder/

Copy foo.txt from /path/to/source/ to /path/to/target/folder/ into a file called bar.txt

Terminal window
cp /path/to/source/foo.txt /path/to/target/folder/bar.txt

copy folder foo into folder bar

Terminal window
cp -r /path/to/foo /path/to/bar

if folder bar exists before issuing the command, then foo and its content will be copied into the folder bar. However, if bar does not exist before issuing the command, then the folder bar will be created and the content of foo will be placed into bar

  • cp [options] source destination
OptionDescription
-a,-archiveCombines the d, p and r options
-b, -backupBefore removal, makes a backup
-d, --no-deferencePreserves links
-f, --forceRemove existing destinations without prompting user
-i, --interactiveShow prompt before overwriting
-l, --linkInstead of copying, link files instead
-p, --preservePreserve file attributes when possible
-R, --recursiveRecursively copy directories