Linux Copy Command Examples

September 8, 2019

How do I copy files under Linux operating systems?

You need to use the cp command to make copies of existing file. The syntax is as follows:

 cp source.file destination.file

cp source.file destination.file


 cp /path/to/file1 /path/to/file2

cp /path/to/file1 /path/to/file2

For example, make a copy of /etc/passwd as /tmp/password.file, enter:

 cp /etc/passwd /tmp/password.file
cat /tmp/password.file

cp /etc/passwd /tmp/password.file
cat /tmp/password.file

To copy file to another system, use scp command:

scp /path/to/file1 user@server1:/tmp

scp /path/to/file1 [email protected]:/tmp

For example, copy /home/vivek/data.txt to server called server1 and into a directory called /home/sales, enter:

scp /home/vivek/data.txt roja@server1:/home/sales

scp /home/vivek/data.txt [email protected]:/home/sales

You must know roja users’ password in order to copy a file.

Copy All Files

To copy all files from /data/sales/*.txt to /backup directory, enter:

cp -avr /data/sales/*.txt /backup

cp -avr /data/sales/*.txt /backup


  • -a : Archive mode and save file permission
  • -v : Verbose mode (show progress)
  • -r : Copy directories recursively

scp vs cp command

  • The scp copies files between hosts on a network.
  • The cp copies files between two directories on same host.

Posted by: SXI ADMIN

The author is the creator of SXI LLC and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Article Tags:
Article Categories:
How To

Comments are closed.