How to tar all files except logs and .txt files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to tar all files except logs and .txt files
# 1  
Old 12-01-2011
How to tar all files except logs and .txt files

Hi

I greatly appreciate the forum and the people here very helpful Smilie

I could able to tar all the directories, sub dirs and the files. But unable to tar all the directories excluding the log and text files. Can anyone please advise the exact command to use for excluding .log and .txt?

PS: There is a huge list of files and directories. I am using solaris.


Best Regards
Olivia
# 2  
Old 12-01-2011
Use find to generate the list of files you want, excluding *.txt and *.log, then pipe it into xargs which will run tar as appropriate.

You need -rf, not -cf, because tar may be run more than once on the same file, and you want it to append, not replace, when it does. This will let it process arbitrary amounts of files.

-I{} tells xargs to take quotes, spaces and commas in arguments literally instead of trying to process them.

Code:
find /path/to/files/ -type f '!' -name '*.txt' '!' -name '*.log' | xargs -I{} tar -rf backup.tar

# 3  
Old 12-06-2011
Quote:
Originally Posted by Corona688
Use find to generate the list of files you want, excluding *.txt and *.log, then pipe it into xargs which will run tar as appropriate.

You need -rf, not -cf, because tar may be run more than once on the same file, and you want it to append, not replace, when it does. This will let it process arbitrary amounts of files.

-I{} tells xargs to take quotes, spaces and commas in arguments literally instead of trying to process them.

Code:
find /path/to/files/ -type f '!' -name '*.txt' '!' -name '*.log' | xargs -I{} tar -rf backup.tar

Thank you so much. It worked for me Smilie
# 4  
Old 12-06-2011
I'm glad you got an answer and it worked, but I have an alternative solution, assuming you've got something similar to the awesome GNU tar on your Solaris boxen:

Code:
tar -cf MYTAR --exclude='*.txt' --exclude='*.log'  DIR

# 5  
Old 12-06-2011
In general, don't depend on having GNU unless you're on Linux.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. HP-UX

HP-UX LOGS Files

hello, i just want to know logs files for these actions listed below : - User Account Creation - User Account Deletion - Failed and or Successful User Password Changes - Failed Login Activities for all User Users - System Reboot or and shutdown help appreciated... (1 Reply)
Discussion started by: Bolou
1 Replies

2. Shell Programming and Scripting

Compare two txt files,mismatches will be in new txt files

Hi, Below are the sample data for txt files. txt file 1 Partnumber|catgroup_id 10001082|46016 10001093|4680 10001093|386003 10001093|463004 10003251|683 10003251|63005 10003252|463005 10003252|4683 10003260|463005 10003260|4683 10003264|4683 10003264|463005 13420000|67... (5 Replies)
Discussion started by: Ankita Talukdar
5 Replies

3. Shell Programming and Scripting

How to create zip/gz/tar files for if the files are older than particular days in UNIX or Linux?

I need a script file for backup (zip or tar or gz) of old log files in our unix server (causing the space problem). Could you please help me to create the zip or gz files for each log files in current directory and sub-directories also? I found one command which is to create gz file for the... (4 Replies)
Discussion started by: Mallikgm
4 Replies

4. Solaris

Command to remove existing files in the tar files in Solaris 10

Hi, I am using solaris 10 OS.Please help me out with the commands needed in below two scenarios. 1)How to delete the existing files in the tar file. suppose i have a main tarfile named application.tar and it contains a file called ingres.tar. what is the command to remove ingres.tar... (2 Replies)
Discussion started by: muraliinfy04
2 Replies

5. Shell Programming and Scripting

tar command to explore multiple layers of tar and tar.gz files

Hi all, I have a tar file and inside that tar file is a folder with additional tar.gz files. What I want to do is look inside the first tar file and then find the second tar file I'm looking for, look inside that tar.gz file to find a certain directory. I'm encountering issues by trying to... (1 Reply)
Discussion started by: bashnewbee
1 Replies

6. Shell Programming and Scripting

moving the files in a.txt files to a different directory

HI All, I am coding a shell script which will pick all the .csv files in a particular directoryand write it in to a .txt file, this .txt file i will use as a source in datastage for processing. now after the processing is done I have to move and archive all the files in the .txt file to a... (5 Replies)
Discussion started by: subhasri_2020
5 Replies

7. Solaris

list files .txt and .TXT in one command

Dear experts, In a directory i have both *.TXT and *.txt files. I have a script- for file in `ls *.txt`; do mv $file /tmp/$file How to list both *.txt and*.TXT file in one command so that script will move both .txt or .TXT whatever it find. br//purple (4 Replies)
Discussion started by: thepurple
4 Replies

8. UNIX for Advanced & Expert Users

How to create a Tar of multiple Files in Unix and FTP the tar to Windows.

Hi, On my Unix Server in my directory, I have 70 files distributed in the following directories (which have several other files too). These files include C Source Files, Shell Script Source Files, Binary Files, Object Files. a) /usr/users/oracle/bin b) /usr/users/oracle... (1 Reply)
Discussion started by: marconi
1 Replies

9. Shell Programming and Scripting

How to process the files using .tar.gz files in script

Hi, I have some file in /users/xyz directoty with .tar.gz extension. i need to find these files and if found in need to run other commands. I now the command for finding files,but how to put if condition ?please help me Thanks (3 Replies)
Discussion started by: bmkreddy
3 Replies

10. UNIX for Advanced & Expert Users

Untaring *.tar.tar files

Hi all, How to untar a file with .tar.tar extension. A utility that i downloaded from net had this extension. Thanks in advance, bubeshj. (6 Replies)
Discussion started by: bubeshj
6 Replies
Login or Register to Ask a Question