Excluding dot files for s3cmd sync

5.4k Views Asked by At

How can I exclude all dot files in my home directory as well as those dot files in all sub-directories?

I've tried adding the following expression in my exclude file, but for some reason it does not work:

(^|/)\.[^/]*(/|$)

Also, the following doesn't work either:

.*
.*/**
1

There are 1 best solutions below

1
On

Please try the following commands with the option --dry-run first to make sure that you get the result you expect.

Exclude .dotfiles and .folders from current directory

You can use the option --rexclude "^\." in order to match files and folders beginning with a . (But it will not match .dotfiles in a sub-directory).

Example output from s3cmd sync --rexclude "^\." ./ s3://bucket_name

exclude: .ignoreFile
exclude: .ignoreFolder/andItsContents
./normalFolder/.ignoreFile -> s3://bucket_name/normalFolder/.ignoreFile

The above command with exclude .dotfiles in your current folder ./ and continue to upload normalFolder/.ignoreFile

Exclude .dotfiles from sub-directories

To exclude dotfiles from a sub-directory you can use --rexclude "\/\."

Example output from s3cmd sync --rexclude "\/\." ./ s3://bucket_name

exclude: .ignoreThis
exclude: .ignoreFolder/.ignoreThis
exclude: .ignoreFolder/notadotfile
exclude: normalFolder/.ignoreThis

So the answer to your question should be similar to the following command:

s3cmd --rexclude "^\." --rexclude "\/\." ./ s3://bucket_name

Explanation of regular expression anchors used:

^   Start of string, or start of line in multi-line pattern
\   Escape following character

Useful Reference:
Regular Expressions Cheat Sheet

s3cmd Sync HowTo