LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 05-18-2008, 07:37 PM   #1
vbsaltydog
Member
 
Registered: Nov 2005
Distribution: CentOS
Posts: 154

Rep: Reputation: 15
exception to * operator?


I am trying to use the tar command to copy everything in my current directory recursively to a tar file for a backup but I don't want to include any .tar files in the backup. Is there a way to exclude .tar files from a tar command with * being the source file to be copied?


Current command:
Code:
tar -cvf ./* backup.tar

Looking for something like:


Code:
tar -cvf ./* (except *.tar) backup.tar

Thanks for the assistance
 
Old 05-18-2008, 07:58 PM   #2
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Assuming that you only want to exclude tar's that live in /

Code:
ls *tar > /exclusions
echo exclusions >> /exclusions
tar -X /exclusions -cvf ./* backup.tar
If you want to exclude ANY tar anywhere in the file-system:

Code:
find / -type f -name \*.tar.\* > /exclusions
echo exclusions >> /exclusions
tar -X /exclusions -cvf ./* backup.tar

Cheers,
Tink
 
Old 05-18-2008, 08:01 PM   #3
vbsaltydog
Member
 
Registered: Nov 2005
Distribution: CentOS
Posts: 154

Original Poster
Rep: Reputation: 15
Thanks Tink
 
Old 05-18-2008, 08:38 PM   #4
vbsaltydog
Member
 
Registered: Nov 2005
Distribution: CentOS
Posts: 154

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by Tinkster View Post
Assuming that you only want to exclude tar's that live in /

Code:
ls *tar > /exclusions
echo exclusions >> /exclusions
tar -X /exclusions -cvf ./* backup.tar
If you want to exclude ANY tar anywhere in the file-system:

Code:
find / -type f -name \*.tar.\* > /exclusions
echo exclusions >> /exclusions
tar -X /exclusions -cvf ./* backup.tar

Cheers,
Tink

I spoke too soon. I am trying to do this backup via a php script that is run from the command line (not as the apache user).

I am running the code using the php exec() function as:


Code:
exec("ls *tar > /exclusions");
exec("echo exclusions >> /exclusions");
exec("tar -X /exclusions -cvf $destfile ./*");
and here is the result:

Code:
sh: /exclusions: Permission denied
sh: /exclusions: Permission denied
tar: /exclusions: No such file or directory
tar: Error is not recoverable: exiting now
Clearly the logged in user does not have permission to write the result of the ls to /exclusions

Any ideas?
 
Old 05-19-2008, 12:04 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,361

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, /exclusions would be at the root of the partition, where traditionally only root can write.
Create a dir path owned by the relevant user
 
Old 05-19-2008, 07:36 AM   #6
vbsaltydog
Member
 
Registered: Nov 2005
Distribution: CentOS
Posts: 154

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by chrism01 View Post
Well, /exclusions would be at the root of the partition, where traditionally only root can write.
Create a dir path owned by the relevant user
I didn't realize that /exclusions was a file. I adjusted the paths in the commands and all is well.

Thanks to everyone.
 
  


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
What is the operator * ./. . . * royeo Linux - Newbie 2 09-03-2006 06:13 PM
help createing exception class from base STL exception qwijibow Programming 4 04-20-2005 05:23 AM
C++ operator += uman Programming 1 02-20-2005 04:37 PM
~ operator linuxanswer Programming 7 04-08-2004 04:56 PM
Runtime Exception vs. Exception mikeshn Programming 1 09-22-2002 05:33 AM

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

All times are GMT -5. The time now is 03:59 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
Open Source Consulting | Domain Registration