cp

cp (GNU) Cheatsheet #

The cp command is used to copy files and directories in Unix-like operating systems.

Basic Commands #

Command/OptionExampleDescription
cp file1 file2cp example.txt backup.txtCopy example.txt to backup.txt
cp -r dir1 dir2cp -r mydir backupdirCopy directory mydir to backupdir
cp -i file1 file2cp -i example.txt backup.txtPrompt before overwriting files
cp -u file1 file2cp -u example.txt backup.txtCopy only when the source file is newer than the destination file

Advanced Options #

Command/OptionExampleDescription
cp -a src destcp -a mydir backupdirArchive mode, copy directories recursively, preserving attributes
cp -p file1 file2cp -p example.txt backup.txtPreserve file attributes (timestamps, ownership)
cp -l file1 file2cp -l example.txt linkfileCreate hard links instead of copying files
cp -v file1 file2cp -v example.txt backup.txtVerbose mode, show files as they are copied

This cheatsheet covers essential GNU cp options for copying files and directories.

cp

Explore our comprehensive cheatsheets to enhance your knowledge and efficiency. Each cheatsheet provides detailed command options, examples, and descriptions to help you master various tools and technologies.