31

Does anybody know if there is an rsync option, so that directories that are being traversed do not show on stdout.

I'm syncing music libraries, and the massive amount of directories make it very hard to see which file changes are actually happening. I'v already tried -v and -i, but both also show directories.

Koen Weyn
  • 989
  • 1
  • 7
  • 12

2 Answers2

34

If you're using --delete in your rsync command, the problem with calling grep -E -v '/$' is that it will omit the information lines like:

deleting folder1/
deleting folder2/
deleting folder3/folder4/

If you're making a backup and the remote folder has been completely wiped out for X reason, it will also wipe out your local folder because you don't see the deleting lines.

To omit the already existing folder but keep the deleting lines at the same time, you can use this expression :

rsync -av --delete remote_folder local_folder | grep -E '^deleting|[^/]$'
Zurd
  • 686
  • 7
  • 16
  • 5
    Good answer. For file syncing, I like to do a dry run before running the command so I use the `-n` option. For readability, I've modified the grep regex to include the blank line, `rsync -av --delete remote_folder local_folder | grep -E '^deleting|[^/]$|^$'` – Anthony Geoghegan Aug 26 '14 at 16:26
  • I've also added `--color=never` to `grep` command the to avoid the unnecessary highlighting of the matched characters. – Roger Dueck Jun 04 '18 at 21:05
14

I'd be tempted to filter using by piping through grep -E -v '/$' which uses an end of line anchor to remove lines which finish with a slash (a directory).

Here's the demo terminal session where I checked it...

cefn@cefn-natty-dell:~$ mkdir rsynctest
cefn@cefn-natty-dell:~$ cd rsynctest/
cefn@cefn-natty-dell:~/rsynctest$ mkdir 1
cefn@cefn-natty-dell:~/rsynctest$ mkdir 2
cefn@cefn-natty-dell:~/rsynctest$ mkdir -p 1/first 1/second
cefn@cefn-natty-dell:~/rsynctest$ touch 1/first/file1
cefn@cefn-natty-dell:~/rsynctest$ touch 1/first/file2
cefn@cefn-natty-dell:~/rsynctest$ touch 1/second/file3
cefn@cefn-natty-dell:~/rsynctest$ touch 1/second/file4

cefn@cefn-natty-dell:~/rsynctest$ rsync -r -v 1/ 2
sending incremental file list
first/
first/file1
first/file2
second/
second/file3
second/file4

sent 294 bytes  received 96 bytes  780.00 bytes/sec
total size is 0  speedup is 0.00


cefn@cefn-natty-dell:~/rsynctest$ rsync -r -v 1/ 2 | grep -E -v '/$'
sending incremental file list
first/file1
first/file2
second/file3
second/file4

sent 294 bytes  received 96 bytes  780.00 bytes/sec
total size is 0  speedup is 0.00
Cefn Hoile
  • 431
  • 2
  • 9
  • 6
    I came to the same conclusion myself. It just seems idiotic that rsync doesn't have a switch to do this. Thanks for the suggestion! – Koen Weyn Dec 20 '11 at 21:07