Linux: HowTo Copy a Folder [Command Line]

cp = copy Command

cp is a Linux command for copying files and directories. The syntax is as follows:

cp source destination
cp dir1 dir2
cp file.txt newfile.txt
cp -option source destination
cp -option1 -option2 source destination

In this example we try to copy /home/USR/some/dir folder and all its files to /home/USR/nfs-mounts directory

cp -avr /home/USR/some/dir /home/USR/nfs-mounts

Where -avr means:

  • -a : Preserve the specified attributes such as directory and file mode, ownership, timestamps, and so on.
  • -v : verbose: Explain what is being done.
  • -r : Copy directories recursively.

Example

Copy a directory called /dir/some/files to /home/USR-123/documents:

$ cp -avr /dir/some/files/ /home/USR-123/documents/