amuck-landowner

How do you exclude a sub-directory via bash?

MannDude

Just a dude
vpsBoard Founder
Moderator
For example, say you want to create an archive of a directory to back it up:

tar -zcf /some/backup/folder/yoursite_www_$(date +"%m_%d-%Y_%H:%M").tar.gz /home/someuser/somesite/public_htmlSo that'll create an an archive of everything located in /home/someuser/somesite/public_html. Great. But what if you have a folder with large files in it that you want to exclude from being backed up? For example: /home/someuser/somesite/public_html/bigfiles ? How would you exclude that from being archived?
 

perennate

New Member
Verified Provider
Good answer: man tar

(or, if you're looking for a replacement for bash wildcard matching that supports exclusion, use find)

Bad answer:

Code:
tar -zcf /some/backup/folder/yoursite_www_$(date +"%m_%d-%Y_%H:%M").tar.gz --exclude=bigfiles /home/someuser/somesite/public_html
 
Last edited by a moderator:

Jack134

Member
find /home/feeds/data -type f -not -path "*def/incoming*" -not -path "*456/incoming*"
  • find /home/feeds/data: start finding recursively from specified path
  • -type f: find files only
  • -not -path "*def/incoming*": don't include anything with def/incoming as part of its path
  • -not -path "*456/incoming*": don't include anything with 456/incoming as part of its path
 
Top
amuck-landowner