find multiple file types and tar


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting find multiple file types and tar
# 1  
Old 02-23-2006
find multiple file types and tar

There are these ksh files and config files that are written and updated on a daily basis.

All I want to do is write a script that finds both these types of files and archive them on a daily basis, to help in restoring in times of system outages and so on. Particulary I'm interested in .ksh , .sql files and .ini files (config)

Please help with a correct procedure to locate these files in a directory and all it's sub-directories, all at the same time and archive them suitably using "tar".

if it's only one type of a file i see the solution as

find dirname -name *.ksh | xargs tar -rf tarfilename

i'm not sure how i can do it for all the file types simultaneoulsy, if at all that's a sensible idea.

any help is appreciated.

TIA,
sirisha
# 2  
Old 02-23-2006
find . -name "*.sql" -o -name "*.ksh" -o -name "*.ini"

use '-o' to create an OR and then pipe to tar like you had above.
# 3  
Old 02-23-2006
Quote:
Originally Posted by DogDay
find . -name "*.sql" -o -name "*.ksh" -o -name "*.ini"

use '-o' to create an OR and then pipe to tar like you had above.

Thank you so much Dogday! just didn't strike me at the moment... Smilie !
# 4  
Old 02-23-2006
But there's a minor correction.. your expression won't work unless the combined saerch pattern is enclosed within parantheses... otherwise the output would only contain the names of files with extension *.ini..

the actual expression is:

find . \( -name "*.ksh" -o -name "*.sql" -o -name "*.ini" \) ...

or else we get only files ending in .ini as the output.

Cheers,
Sirisha
# 5  
Old 02-25-2006
Well perhaps your shell makes the difference. It works fine for me but I think the parenthesis appears more proper.
# 6  
Old 02-27-2006
More help pls!!!

Infact, the expression worked fine, but what puzzles me now is the following tar

This is my shell script...

Archive=`(date +%Y%m%d)`
if [ -d searchdir ]
then
find searchdir -type f \( -name \*\.ksh -o -name \*\.sql -o -name \*\.ini \) | xargs tar -rf $Archive.tar
else
echo "searchdir is not a dir"
fi

The objective is to search for these file types on a daily basis and archive them into a tar file named with the corresponding date.

Any clues of where I'm mistaken?!

Regards
Sirisha
# 7  
Old 02-27-2006
sorry.. i didn't explain my problem up there..

the error is " 20060224.tar: No such file or directory exists"

If i change the option of tar to -cf then the tar will be created but it is either empty (the searchdir has non-zero files of the desired extensions) or is non extractable, or even sometimes says "tar: Missing filenames"

if at all if the tar is created, i use tar -xvf 20060224.tar and see nothing!!

Getting back to the basics now..

I think i'm even wrong with my search pattern.. the expression doesnt just search for the required file types but includes all files in the directory along with the desired ones. Smilie

Can anyone Please suggest an answer?!

Despo for help,
TIA again!!

Last edited by manthasirisha; 02-27-2006 at 02:13 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script to find file types and info

I'm looking for a way to inventory files on a webserver into a CSV file, and am particularly interested in certain types of files, like .php, .cgi, .pl, .py, .sh, etc. but also want the ability to find all files, including those with no extension, or specified extensions, as above, including files... (1 Reply)
Discussion started by: spacegoose
1 Replies

2. Shell Programming and Scripting

Using a single "find" cmd to search for multiple file types and output individual files

Hi All, I am new here but I have a scripting question that I can't seem to figure out with the "find" cmd. What I am trying to do is to only have to run a single find cmd parsing the directories and output the different file types to induvidual files and I have been running into problems.... (3 Replies)
Discussion started by: swaters
3 Replies

3. Shell Programming and Scripting

bash: find multiple types[solved]

Hi, I would like to use find to search for multiple types. For example search for symlink and regular file but not directories, sockets etc.... Something like: find . -type l,f -name "stuff" But of course it does not work. Is there any way to avoid an if statement and to do it faster? ... (0 Replies)
Discussion started by: Dedalus
0 Replies

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

5. Shell Programming and Scripting

How to pass multiple file types search pattern as argument to find?

How can I pass $var_find variable as argment to find command? test.sh var_find=' \( -name "*.xml" -o -name "*.jsp" \) ' echo "${var_find}" find . -type f ${var_find} -print # Below statement works fine.. I want to replace this with the above.. #find . \( -name "*.xml" -o -name... (4 Replies)
Discussion started by: kchinnam
4 Replies

6. Linux

Simplified find command to find multiple file types

Hi, I'm using the following command to find the multiple requierd file types and its working fine find . -name "*.pl" -o -name "*.pm" -o -name "*.sql" -o -name "*.so" -o -name "*.sh" -o -name "*.java" -o -name "*.class" -o -name "*.jar" -o -name "*.gz" -o -name "*.Z" -type f Though... (2 Replies)
Discussion started by: vickramshetty
2 Replies

7. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 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. Solaris

How to add multiple tar file to a script

I have appended a tar file to my installation script so that while installing i can unzip from there (specifying the starting line number) and install a package. This work fine if i add one tar file. But suppose i have to install different packages depending on the platform the script is run. i... (0 Replies)
Discussion started by: vikashtulsiyan
0 Replies

10. UNIX for Dummies Questions & Answers

finding multiple file types with "-o"

i was just wondering if any one had a good example of finding mutliple file types with the -o option or any other alternatives. find . \( -name "*.txt" -o -name "*.tag" \) for some reason i'm not having much luck and the man page isn't very descriptive. what i am trying to do is find all... (6 Replies)
Discussion started by: Shakey21
6 Replies
Login or Register to Ask a Question