• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How to Create tar Archive excluding some Files & Directories

Written by akhil, Updated on October 7, 2019

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.

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
    

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Avatar
akhil

1 Comment

  1. Avatar Manoj Gupta Reply
    July 8, 2019 at 10:28 am

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

    Then what would be option?

Leave a Reply Cancel reply

Popular Posts

  • How To Install Python 3.9 on Ubuntu 20.04 5
  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
  • How To Install NVM on macOS with Homebrew 0
  • (Solved) apt-add-repository command not found – Ubuntu & Debian 0
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy