I'm a new Linux user. How do I copy a directory or folder under Linux operating system using command line options and bash shell?
You can use various command to copy a folder under Linux operating systems.
cp Command
cp is a Linux command for copying files and directories. The syntax is as follows:
cp source destination cp dir1 dir2 cp -option source destination cp -option1 -option2 source destination
In this example copy /home/vivek/letters folder and all its files to /usb/backup directory:
cp -avr /home/vivek/letters /usb/backup
Where,
- -a : Preserve the specified attributes such as directory an file mode, ownership, timestamps, if possible additional attributes: context, links, xattr, all.
- -v : Explain what is being done.
- -r : Copy directories recursively.
Example
Copy a folder called /tmp/conf to /tmp/backup:
$ cp -avr /tmp/conf/ /tmp/backup
Sample outputs:
rsync Command
You can also use rsync command which is a fast and extraordinarily versatile file copying tool. It can make copies across the network. The syntax is as follows:
rsync -av /path/to/source /path/to/destination rsync -av /path/to/source/ /path/to/destination/source
To backup my home directory, which consists of large files and mail folders to /media/backup, enter:
$ rsync -avz /home/vivek /media/backup
I can copy a folder to remote machine called server1.cyberciti.biz:
$ rsync -avz /home/vivek/ server1.cyberciti.biz:/home/backups/vivek
Where,
- -a : Archive mode i.e. copy a folder with all its permission and other information including recursive copy.
- -v : Verbose mode.
- -z : With this option, rsync compresses the file data as it is sent to the destination machine, which reduces the amount of data being transmitted — something that is useful over a slow connection.
You can show progress during transfer using --progress or -P option:
$ rsync -av --progress /path/to/source/ /path/to/dest
Sample outputs:
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop


![Copy Folder Linux Commands [ rsync ] Copy Folder Linux Commands [ rsync ]](http://files.cyberciti.biz/uploads/faq/2012/04/copy-folder-linux-commands-rsync..png)



![Unix Copy Command Examples [ cp command ]](http://s13.cyberciti.org/images/shared/rp/3/13.jpg)



![Linux Copy File Command [ cp Command Examples ]](http://s13.cyberciti.org/images/shared/rp/3/9.jpg)


{ 3 comments… read them below or add one }
i am a beginner in computer repairs,i like u to update me also on linux usage nd repairs.
“r” in “cp -ar” is redundant. -a implies -r.
I confirm that cp does the same with or without r.