Exclude a directory to tar

If use tar file from a directory , how to exclude a sub-directory in this directory ?

ll
drw-r--r-- 1 root root 4096 Oct 12 11:58 b
drw-r--r-- 1 root root 4096 Oct 12 10:54 c
drwxr-xr-x 2 root root 4096 Oct 12 11:57 d
drw-r--r-- 1 root root 4096 Oct 12 10:54 d
eg . I want to tar all files under the above directory but exclude the sub-directory "c" ( not exclude file ) , could advise how to do it ? thx

Which Operating System are you using (uname -a) - so we know whether we're dealing with GNU tar or not....

Cheers
ZB

common style using "tar+exclude" suggested in internet sources is like:

tar \

  • -exclude� \
  • -exclude� \
  • -exclude� \
  • -exclude� \
    -cvpzf home_bup.tgz /home/username

but i think it is a very annoying method.

I suggest next:

for fedora core

tar cvpzPf /tmp/backup.tar.gz �exclude={/proc/*,/sys/*,/tmp/*,/dev/*} /

for Debian

tar cvfpP /tmp/debian2.tar �exclude={�/proc/*�,�/sys*�,�/tmp/*�,�/home/user/*�} /

and more common if i need backup using ssh (ssh+nice+tar)

ssh root@192.168.0.1 �cd /;nice -n 10 tar cvpP �exclude={�/proc/*�,�/sys*�,�/tmp/*�,�/home/user/*�} /�>backup.tar.gz

:slight_smile:

and before "exclude" we have two "-" not one.