Reputation: 135
This is my current directory structure on my MacOSX-Machine:
kuli at fumpenwuppich in /volume/workspace on master [!?$]
$ ls -l
total 0
drwxr-xr-x 4 kuli staff 136 Nov 28 16:02 conf
drwxr-xr-x 3 kuli staff 102 Nov 28 16:23 html
drwxr-xr-x 3 kuli staff 102 Nov 28 13:06 legacy
drwxr-xr-x 11 kuli staff 374 Nov 28 15:41 vagrant.nginx
I want to create a tar.bz2-file as a backup, but without the sub directory 'legacy'.
I've tried multiple things:
tar cfjv --exclude 'legacy' ~/Dropbox/backup/kuli.20151128.tar.bz2 .
tar cfjv --exclude='legacy' ~/Dropbox/backup/kuli.20151128.tar.bz2 .
tar cfjv ~/Dropbox/backup/kuli.20151128.tar.bz2 --exclude legacy .
tar cfjv ~/Dropbox/backup/kuli.20151128.tar.bz2 --exclude=legacy .
tar cfjv ~/Dropbox/backup/kuli.20151128.tar.bz2 --exclude='legacy' .
tar cfjv ~/Dropbox/backup/kuli.20151128.tar.bz2 --exclude './legacy' .
tar cfjv ~/Dropbox/backup/kuli.20151128.tar.bz2 --exclude='./legacy' .
tar cfjv ~/Dropbox/backup/kuli.20151128.tar.bz2 --exclude 'workspace/legacy' .
and so on. I've also tried to put the exlude-switch at the end of the command.
But nothing worked. All commands ignore the exclude command at all.
How to achieve this?
Upvotes: 13
Views: 10145
Reputation: 181
Curiously, I could not get this to work on Mac OS X (version 10.11.5) until I rearranged the order of parameters to something like
tar --exclude '/subdir1/' --exclude '/subdir2/' -zcvf "mybackup.tar.gz" ./myfolder
Upvotes: 18
Reputation: 4681
According to man page options go before files and directories list:
tar {-c} [options] [files | directories]
Additionally -f
and --exclude
options require parameters: -f file
and --exclude pattern
.
So, in your case, this should work:
tar cjv --exclude 'legacy' -f ~/Dropbox/backup/kuli.20151128.tar.bz2 .
Upvotes: 17