Copy Files and Folders on Linux

cp [Option] [Source] [Destination]

+----------------------------------------------------------+
| Option | Description |
+----------------------------------------------------------+
| -v | Verbose mode (Show Progress) |
| -r/R | Copy Directories Recursively |
| -n | Don't overwrite an existing file |
| -d | Copy a link file |
| -i | Prompt before overwrite |
| -p | Preserve the specified attributes |
| -b | Make a backup of each existing destination file |
+----------------------------------------------------------+

Copy a File from One Location to Another in Linux Using the cp Command

cp /home/source/demo.txt /home/destination“cp” - Copy Command
“/home/source/demo.txt” - Source
“/home/destination” - Destination

Copy a File from One Location to Another With a Different Name on Linux Using the cp Command

cp /home/source/demo.txt /home/destination/demo1.text“cp” - Copy Command
“/home/source/demo.txt” - Source
“/home/destination/demo1.txt” - Destination

Copy Multiple Files from One Location to Another in Linux Using the cp Command

# cp /home/source cp-demo.txt cp-demo-1.txt cp-demo-9.txt /home/destination/

Copy a Directory Recursively from One Location to Another in Linux Using the cp Command

cp -r /home/source/demo-folder/ /home/destination/

Copy Multiple Folders on Linux Using the cp Command

cp -r /home/source/demo-folder/ /home/another_folder/public_html/ /home/destination_folder/test

Copy All Files from One Location to Another in Linux Using “wildcard (*)”

cp /home/source/* /home/destination/

Copy All Files and Folders from One Location to Another in Linux Using “wildcard (*)”

cp -R /home/source/* /home/destination/

Copy All Files, Including Hidden Files (“.” Dot Files) in Linux Using the cp Command

cp -R /home/source/.* /home/destination/all-files/

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store