Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rsync copy directory contents but not directory itself

Tags:

rsync

People also ask

How do I copy only the contents of a folder in Linux?

The “cp” command is one of the commonly used commands to perform the copy operation. You can copy files or folders from source to destination, i-e, one directory through this command. The syntax of the “cp” command is: $ cp [options] [source…]

Does rsync sync in both directions?

rsync works in one direction, so we need to run it twice to sync directories in both directions.

How do I rsync a folder to another directory?

If you want to copy a directory with its sub-directory and all contents from one location to another within your system, you can do so as by typing rsync followed by the source and destination directory. Note: Specifying “/” after the source directory only copies the contents of the directory.

Why is rsync skipping directory?

Similarly, the rsync skipping directory error can occur when miss to put it into a recursive mode like -r or -a. In addition, use -a instead of -r. -a means to reproduce file hierarchies, including special files and permissions. Also, the option -r only to recurse on directories whereas -a needed for a data backup.


rsync interprets a directory with no trailing slash as copy this directory, and a directory with a trailing slash as copy the contents of this directory.

Try rsync -av ~/foo/ [email protected]:/var/www/bar/


It's simple,

rsync /var/www/ /home/var - copies the contents of /var/www/ but not the www folder itself.

rsync /var/www /home/var - copies the folder www along with all its contents.

The "/" makes the difference.


Not related only to rsync, but when you are looking for examples on how to use a GNU/Linux command, you can use "eg" which displays explicit examples. eg is available here, with instructions on how to install it: https://github.com/srsudar/eg

The result for eg rsync is as follow

# rsync


copy the folder source_dir and its content into destination_dir

    rsync -av source_dir destination_dir


copy the contents of source_dir (trailing slash) into destination_dir

    rsync -av source_dir/ destination_dir

Navigate into the directory you would like to copy over, so:

cd ~/foo 

Run this:

rsync -avz . [email protected]:/var/www/bar