Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Linux Commands»How to Create tar Archive excluding some Files & Directories

    How to Create tar Archive excluding some Files & Directories

    By akhilOctober 7, 20191 Min Read

    Tar Command:

    tar czf backup.tar.gz --exclude "wp-content/cache" public_html
    

    Above command will archive all files and directories under public_html directory except wp-content/cache directory and create a archive file named backup.tar.gz.

    Advertisement

    Examples

    • Exclude a single directory inside other directory. Create archive of all files under public_html directory ignoring all files and folders including text backup in there named
      tar czf backup.tar.gz --exclude "wp-content/uploads" public_html
      
    • You can define multiple exclude in single command. For example create and archive of all files under public_html directory ignoring .svn or .git files and directories.
      tar czf backup.tar.gz --exclude ".svn" --exclude ".git" public_html
      
    • To exclude a specific file define full path of the file. For example exclude “logs/access.log” inside public_html directory.
      tar czf backup.tar.gz --exclude "logs/access.log" public_html
      
    • Create archive of all files under public_html directory ignoring all files and directories starting with dot ( . ) (hidden files).
      tar czf backup.tar.gz --exclude "*.log" public_html
      

    archive compress tar
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Top 10 JQ Commands Every Linux Developer Should Know

    How to Check if a Program Exists in Linux

    How to Create a Directory If It Does Not Exist in Linux

    View 2 Comments

    2 Comments

    1. Manoj Gupta on July 8, 2019 10:28 am

      You are excluding through keyword. Suppose, if I want to exclude a particular path folder only.

      Then what would be option?

      Reply
      • Chris on August 8, 2021 11:49 am

        Had the same question. The solution I found is:
        1. use the absolute path to the folder you want to exclude
        2. put the –exclude statement at the beginning of the command (before the “czf” stuff)

        Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.