0

I am trying to Rsync some files and folders to a remote server with the command as:

rsync -rtOzv --partial -e ssh /media/external/Media/ user@serverip:/media/external/Media  --exclude-from='/srv/mr/logs/ExcludeList.txt' --log-file=/srv/mr/logs/RSyncLog.txt

with ExcludeList.txt containing the following:

testfolder1
test folder 2
test - folder - 3
test [folder4]
testfile1.txt
test file 2.txt
test - file - 3.txt
test [file4].txt

When I run the command, test [folder4] and test [file4].txt still get transferred to remote folder. How can I exclude the files/folders that contain [ or ] in its name?

2 Answers 2

3

The manual page says

--exclude-from=FILE     read exclude patterns from FILE

Note the word patterns. The exclude list does not consist of mere file names, but patterns. Try backslashes:

test \[folder4\]
2

From the rsync man page, "INCLUDE/EXCLUDE PATTERN RULES" section:

  • a '[' introduces a character class, such as [a-z] or [[:alpha:]].
  • in a wildcard pattern, a backslash can be used to escape a wildcard character, but it is matched literally when no wildcards are present. This means that there is an extra level of backslash removal when a pattern contains wildcard characters compared to a pattern that has none. e.g. if you add a wildcard to "foo\bar" (which matches the backslash) you would need to use "foo\\bar*" to avoid the "\b" becoming just "b".

This means that [file4] will be treated as a pattern that matches any of the single characters "f", "i", "l", "e", or "4". To get the square-brackets to be treated literally, you need to escape them, like: test \[file4\].txt.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .