How do you exclude a sub-directory via bash?

Discussion in 'Coding, Scripting & Programming' started by MannDude, Oct 14, 2015.

Tags:
  1. MannDude

    MannDude Just a dude vpsBoard Founder Moderator

    5,007
    2,620
    Mar 8, 2013
    MannDude
    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?
     
  2. perennate

    perennate New Member Verified Provider

    387
    106
    May 15, 2013
    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: Oct 14, 2015