Wednesday, August 28, 2013

Copy a folder linux


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:
HowTO: Copy Folder Linux Terminal Command
Fig.01: cp command in action

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:
Copy Folder Linux Commands [ rsync ]
Fig.02: rsync command in action

Related Posts:

  • Cấu hình dns domain . Primary Name Server (PNS) Mỗi miền phải có một Primary Name Server (PNS). Server này được đăng ký trên Internet để quản lý miền. Mọi người trên Internet đều biết tên máy tính và địa chỉ IP của server này. Người quản trị D… Read More
  • Một số lệnh check ddos Mã:netstat -n | grep :80 |wc -lKiểm tra số lượng connection đang ở trạng thái SYN_RECV:Mã:netstat -n | grep :80 | grep SYN_RECV|wc -lHiển thị tất cả các IP đang kết nối và số lượng kết nối từ mỗi IP:Mã:netstat -an|grep :80 … Read More
  • Cấu hình và sử dụng các log files của hệ thốngNguồn: Section 18.3, chương 18, phần II - LPI Nhiều sự kiện xảy ra trên hệ thống Linux của bạn nên được log lại cho mục đích quản trị. Linux sử dụng hệ thống syslogd để hiển thị và lưu thông tin miêu tả về các … Read More
  • Giới thiệu về Unix processLà một kỹ sư lập trình hệ thống, một server guy, hay là một sys admin, sys dev, sys ops,… phần lớn thời gian bạn sẽ phải làm việc trên hệ thống Unix. Để làm việc trên Unix, chúng ta tương tác với hệ điều hành thông qua các… Read More
  • REGULARLY FLUSHING THE MYSQL QUERY CACHE When we analyze our customers systems we see typically a high fragmentation of the query cache after a while. This leads to a less optimal use of the Query Cache than possible. With the following Query you can see the value… Read More