LinuxQuestions.org
Visit Jeremy's Blog.
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: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910Reputation: 910
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: Centos 6.9, Centos 7.3
Posts: 17,362

Rep: Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377Reputation: 2377
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


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
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


All times are GMT -5. The time now is 03:55 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