LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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-25-2003, 05:11 AM   #1
murshed
Member
 
Registered: Jan 2002
Posts: 157

Rep: Reputation: 30
tar and excluding files


i asked this question before but i didn't get an answer that would do what i need ..

i have a very huge directory ... and i want to zip this huge directory with excluding some (directories) .. i want to exclude some directories not file ... i repeat .. excluding directories .. not files ..

how possible is it?

well .. i didn't find it yet possible .. i knew how to exclude only one file ..
like this:
tar -cvf file.tar temp/ --exclude temp/CASEtest.sh

this would only exclude CASEtest.sh

how can i exclude all files in that directory that has .sh ? or even exclude two files ?
i did:
tar -cvf file.tar temp/ --exclude temp/*.sh

but it didn't work ..

tar -cvf file.tar temp/ --exclude temp/CASEtest.sh --exclude temp/shell.sh

didn't work

please don't tell me : man tar
cause i did it more than once with no use ..

thanks

Last edited by murshed; 01-25-2003 at 05:13 AM.
 
Old 01-25-2003, 08:15 AM   #2
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Rep: Reputation: 58
this will backup everything excluding /proc and /backups


cd /; tar -cvf /backups/sys1_012503.tar . --exclude proc --exclude backups
 
Old 01-25-2003, 08:24 AM   #3
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Rep: Reputation: 58
examples:


/testtar$ ls -R
.:
test1/ test2/ test3/

./test1:
test1a test1b test1c

./test2:
test2a test2b test2c

./test3:
test3a test3b test3c
david@slacker:~/testtar$ tar -cvf test.tar . --exclude test2
./
./test1/
./test1/test1a
./test1/test1b
./test1/test1c
./test3/
./test3/test3c
./test3/test3b
./test3/test3a
tar: ./test.tar: file is the archive; not dumped

david@slacker:~/testtar$ tar -cvf test.tar . --exclude test2 --exclude test*b
./
./test1/
./test1/test1a/
./test1/test1c/
./test3/
./test3/test3a/
./test3/test3c/
tar: ./test.tar: file is the archive; not dumped


david@slacker:~/testtar$ tar -cvf test.tar . --exclude test2 --exclude test3/test*b
./
./test1/
./test1/test1a/
./test1/test1b/
./test1/test1c/
./test3/
./test3/test3a/
./test3/test3c/
tar: ./test.tar: file is the archive; not dumped

Last edited by DavidPhillips; 01-25-2003 at 08:39 AM.
 
Old 01-25-2003, 09:36 AM   #4
murshed
Member
 
Registered: Jan 2002
Posts: 157

Original Poster
Rep: Reputation: 30
thanks alot .. it worked fine!

but look at this command and tell me please why it didn't work this time

[murshed@localhost murshed]$ tar -cvf test.tar testing1/ --exclude testing1/temp --exclude testing1/shel*
testing1/
testing1/backup.sh
testing1/shell.sh
testing1/CASEtest.sh
testing1/file.tar
testing1/temp.tar
testing1/shell.sh



the temp dir is excluded .. but shel* isn't
 
Old 01-25-2003, 03:42 PM   #5
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Rep: Reputation: 58
the problem is you are adding / to the file name testing1/ instead of testing1

Think of folders as files. Only use a / to specify a path to a file
 
Old 01-26-2003, 05:06 AM   #6
murshed
Member
 
Registered: Jan 2002
Posts: 157

Original Poster
Rep: Reputation: 30
thanks i will try
 
Old 03-14-2003, 06:26 AM   #7
rkrijger
LQ Newbie
 
Registered: Mar 2003
Posts: 17

Rep: Reputation: 0
Quote:
Originally posted by murshed
thanks i will try
Unfortunately, this solutions excludes all proc (and backup) directories on the system. How can I achieve that *only* the /proc is excluded from the tar file and *not* (for example) the /home/rdk/proc directory???
 
Old 03-15-2003, 02:32 PM   #8
DavidPhillips
LQ Guru
 
Registered: Jun 2001
Location: South Alabama
Distribution: Fedora / RedHat / SuSE
Posts: 7,163

Rep: Reputation: 58
That's a very good point Robin

For this reason it is going to require you to use the path

Code:
cd /; tar -cvf /backups/sys1_012503.tar . --exclude ./proc --exclude ./backups
 
  


Reply



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
remove files excluding those with specified extensions Melsync Linux - General 17 08-14-2015 05:16 AM
a tough question 4 u, problem in extracting tar & tar.gz files p_garg Linux - General 5 11-08-2010 11:02 AM
Complex cp : only *.jpg files while excluding DIRs LancerNZ Linux - General 3 02-16-2005 03:12 AM
tar, excluding directories recursively towlie Linux - Newbie 3 06-17-2004 12:32 PM
Excluding directories from zip files jonathanztaub Linux - General 1 05-17-2004 02:17 AM

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

All times are GMT -5. The time now is 07:40 PM.

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
Open Source Consulting | Domain Registration