I am looking for to only sync directories structures only. How do I copy directory structure tree without copying any files under Linux or UNIX operating system to remove server or local directory?
You need to use the rsync command. The rsync remote-update protocol allows rsync to transfer just
the differences between two sets of files across the network connection, using an efficient checksum-search algorithm. Make sure it is installed on all servers for remote copy. The syntax is as follows to copy directories tree only:
rsync -av -f"+ */" -f"- *" /path/to/src /path/to/dest/ rsync -av -f"+ */" -f"- *" /path/to/apache/logs/ root@www433.nixcraft.net.in:/path/to/apache/logs/
If you are using an older rsync version, try:
rsync -av --include='*/' --exclude='*' /path/to/src /path/to/dest/ rsync -av --include='*/' --exclude='*' /path/to/apache/logs/ root@www433.nixcraft.net.in:/path/to/apache/logs/
rsync Command For Directory Structures / Tree Only
Consider the following layout in /var/logs/apache/ for each domain:
cricketnow.in/ cyberciti.biz/ hexindia.net/ io9.in/ nixcraft.com/ theos.in/
You can sync just directories by excluding everything else. Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following commands or login using ssh to the remote server. You want to copy all dirs i.e. exclude everything that is not a directory, enter:
# cd /var/log/apache/
# rsync -av -f"+ */" -f"- *" . root@server2.nixcraft.com:/var/log/apache/
Sample outputs:
building file list ... done ./ cricketnow.in/ cyberciti.biz/ hexindia.net/ io9.in/ nixcraft.com/ theos.in/ sent 388 bytes received 98 bytes 972.00 bytes/sec total size is 0 speedup is 0.00
You can also make local copies as follows:
# cd /var/log/apache/
# rsync -av -f"+ */" -f"- *" . /jailfs/apache/httpd_root/var/log/apache/
See also:
If you need assistance with Linux / UNIX rsync command-line options, turn to the man page first. It will give you detailed information, parameters and switches for rsync command:
$ man rsync
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








![Linux: HowTo Copy a Folder [ Command Line Option ]](http://s13.cyberciti.org/images/shared/rp/3/19.jpg)




{ 4 comments… read them below or add one }
Excellent. Rsyncing the directory structure only was exactly what I needed!
Thank you! :)
Really Great, helps me a lot
Thank you friend
Awesome………nodoubt the needed solution