Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I know rsync has an --exclude option which I use quite frequently. But how can I specify that it should exclude all "numeric" directories?

In the directory listing below I would like to only have it copy css,html,and include

.
..
123414
42344523
345343
2323
css
html
include

Normally my syntax is something like

rsync -avz /local/path/ user@server:/remote/path/ --exclude="cache"

I think it should look something like --exclude="[0-9]*" but I don't think that will work.

share|improve this question

4 Answers 4

up vote 3 down vote accepted

rsync's exclude option doesn't really support regex, it's more of a shell globbing pattern matching.

if those directories are fairly static, you should just list them in a file, and use --exclude-from=/full/path/to/file/exclude_directories.txt.

Updated to provide example

First, you just put the directories into a file:

find . -type d -regex '.*/[0-9]*$' -print > /tmp/rsync-dir-exlcusions.txt

or

( cat <<EOT
123414
42344523
345343
2323
EOT ) > /tmp/rsync-directory-exclusions.txt

then you can do your rsync work

rsync -avHp --exlude-from=/tmp/rsync-directory-exclusions.txt /path/to/source/ /path/to/dest/

You just need an extra step to set up the text file that contains the exclude directories, 1 per line.

keep in mind that the path of the directories in the job, is their relative path to how rsync see's the directory.

share|improve this answer
1  
You could use a script which uses a regex to create this file before running the rsync –  Rory Alsop Oct 5 '11 at 15:57
    
Could you give an example as an answer? –  cwd Oct 5 '11 at 18:27
    
just updated to include an example, including what @RoryAlsop suggested combined with what thiton suggested below. –  Tim Kennedy Oct 5 '11 at 19:40

You can't say “a name that contains only digits” in rsync's pattern syntax. So include all names that contain a non-digit and exclude the rest.

rsync --include='*[!0-9]*' --exclude='*/' …

See also my rsync pattern guide.

share|improve this answer
    
thanks for the link to your rsync pattern guide. –  Tim Kennedy Oct 6 '11 at 14:56

You can do it in one line:

rsync -avHp --exclude-from=<(cd /path/to/source; find . -type d -regex './[0-9]*' | sed -e 's|./||') /path/to/source/ /path/to/dest/
share|improve this answer

Use find to make a list of the directories to be excluded, then use rsync's --exclude-from option as Tim Kennedy described it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.