Linux: rsync Copy Directories Structures Tree Only

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/

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/

rsync Command For Directory Structures / Tree Only

Consider the following layout in /var/logs/apache/ for each domain:

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"- *" .

Sample outputs:

building file list ... done

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

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04

8 comments… add one
  • Dans Jan 14, 2012 @ 11:13

    Excellent. Rsyncing the directory structure only was exactly what I needed!

  • Pablo Aug 26, 2012 @ 22:40

    Thank you! :)

  • Deepak Sep 4, 2012 @ 21:03

    Really Great, helps me a lot
    Thank you friend

  • srivay Nov 29, 2012 @ 15:19

    Awesome………nodoubt the needed solution

  • h4unt3r Nov 1, 2013 @ 18:04

    You can use a find command for this if you want the whole directory tree, not just the top level. Of course when pushing a structure remotely its better to manipulate locally then push:

    find -type d -exec mkdir -p /{} \;

    This will copy the directory structure of to under the dir.

    Isn’t the find command wonderful?!

  • Gabriel Jan 23, 2014 @ 17:30

    gracias, genial!

  • Roberto Nov 9, 2014 @ 2:37

    Thank you, it worked yust nice :D

  • David Oct 22, 2016 @ 2:44

    Thank you so much for this, it was exactly what we needed and worked so much faster than what we were trying to do before your solution !

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.