LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-17-2019, 09:49 AM   #1
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 193

Rep: Reputation: 35
tar - How to exclude multiple directories


Hello

I want to backup a directory, but I don't know how to exclude some directories.

I have this
Code:
$ pwd
/dc

$ ls -lh images
drwxr-xr-x. 2 test test 4.0K Nov 12 22:52 Avatar
drwxr-xr-x. 2 test test 4.0K Jan 17 20:44 Background
drwxr-xr-x. 2 test test 4.0K Jan 17 20:43 Icons
drwxr-xr-x. 4 test test 4.0K Feb 24  2017 Projects
drwxr-xr-x. 2 test test 4.0K Jun  9  2018 Terminal
drwxr-xr-x. 2 test test  12K Jan 11 20:36 Wallpapers
drwxr-xr-x. 2 test test 4.0K Nov 22 10:56 Wallpapers - Lock
drwxr-xr-x. 2 test test 4.0K Aug  5 13:18 Wallpapers - Mobile
I want to take backup of all directories except with Wallpapers.

So I issued this command.
Code:
$ XZ_OPT=-9 tar -cvJf images.tar.xz --exclude='/dc/images/Wallpapers' --exclude='/dc/images/Wallpapers - Lock' --exclude='/dc/images/Wallpapers - Mobile' images/
It's not working. It's not excluding Wallpaper* directories.

I can create an archive by going within 'images' folder first and then selecting specific folders that I want though. But I don't want like that.

Any help appreciated. Thanks
 
Old 01-17-2019, 10:20 AM   #2
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,160
Blog Entries: 3

Rep: Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060Reputation: 2060
Are you remembering to include the asterisk in your option --exclude='/dc/images/Wallpapers*' so that globbing is used?

Last edited by Turbocapitalist; 01-17-2019 at 10:24 AM.
 
1 members found this post helpful.
Old 01-17-2019, 10:35 AM   #3
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 193

Original Poster
Rep: Reputation: 35
Quote:
Originally Posted by Turbocapitalist View Post
Are you remembering to include the asterisk in your option --exclude='/dc/images/Wallpapers*' so that globbing is used?
Tried. Not working.
Code:
$ XZ_OPT=-9 tar -cvJf images.tar.xz --exclude='/dc/images/Wallpapers*' images/
images/
images/Wallpapers - Lock/
images/Wallpapers - Lock/vault.jpg
images/Wallpapers - Lock/ws_Lock_1920x1080.jpg
images/Wallpapers - Lock/QRWbwu.jpg
images/Background/
images/Background/lock.png
images/Background/blue.png
images/Terminal/
images/Terminal/terminal.jpeg
images/Terminal/The-Flash-logo-HD-Wallpaper.jpg
images/Terminal/7036581-black-wallpaper-hd.jpg
images/Icons/
images/Icons/windows.png
images/Icons/debian.png
images/Icons/redhat-white-225x80.png
images/Icons/centos_fancy_24.png
images/Icons/oracle.png
images/Icons/RedHat.svg_.png
images/Icons/suse.png
images/Icons/RedHat-248x80.png
images/Icons/freebsd.png
images/Icons/centos_fancy_48.png
images/Icons/centos_fancy_32.png
images/Icons/redhat.png
images/Icons/sl-logo-128.png
images/Icons/redhat-white.png
images/Icons/ubuntu.png
images/Icons/centos_fancy.png
images/Icons/Redhat_ddj.png
images/Wallpapers - Mobile/
images/Wallpapers - Mobile/1.jpg
images/Wallpapers - Mobile/iphone-6-wallpapers-hd-694px7v3-1080x1920.jpg
images/Wallpapers - Mobile/074ea2885318037b764178e7f8c03b11.jpg
images/Wallpapers - Mobile/Xperia-Z4-Lockscreen-WP-Black.jpg
images/Wallpapers/
images/Wallpapers/3.jpg
images/Wallpapers/spider_man_logo_captain_america_civil_war_color_by_icongfx-da2489q.jpg
images/Wallpapers/google-material-design-wallpaper-1600-900.jpg
images/Wallpapers/lamborghini_aventador_lp700_1-wide.jpg
images/Wallpapers/sunset-5.jpg
images/Wallpapers/spring-rain-background-1920x1200.jpg
.
.
.
 
Old 01-17-2019, 10:36 AM   #4
l0f4r0
Member
 
Registered: Jul 2018
Location: Paris
Distribution: Debian
Posts: 854

Rep: Reputation: 286Reputation: 286Reputation: 286
Absolute paths seems to be your issue here. Try the following (from /dc):
Code:
XZ_OPT=-9 tar cvJf images.tar.xz --exclude="images/Wallpapers*" images/
 
1 members found this post helpful.
Old 01-17-2019, 10:40 AM   #5
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 193

Original Poster
Rep: Reputation: 35
Quote:
Originally Posted by l0f4r0 View Post
Absolute paths seems to be your issue here. Try the following (from /dc):
Code:
XZ_OPT=-9 tar cvJf images.tar.xz --exclude="images/Wallpapers*" images/
Hmmm. Now working.

Thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] tar with --exclude and/or --exclude-from vbekker Linux - Newbie 6 12-09-2010 02:51 AM
CVS Exclude : Exclude sub directories from check out On Linux from command line shajay12 Linux - Newbie 1 08-03-2009 12:36 AM
BackUp & Restore with TAR (.tar / .tar.gz / .tar.bz2 / tar.Z) asgarcymed Linux - General 5 12-31-2006 02:53 AM
tar --exclude --exclude-from cefn Linux - Software 4 10-11-2005 07:31 PM
Exclude directories when backing up with 'tar'? wolfpeach Linux - Newbie 2 06-28-2004 10:54 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:02 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration