Find most recent files in dirs and tar them up?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find most recent files in dirs and tar them up?
# 1  
Old 04-06-2009
Find most recent files in dirs and tar them up?

Hey all.. This should be simple but stoopid here can't get head around it! I have many directories, say 100 each with many files inside. I need a script to traverse through the dirs, find most recent file in each dir and add it to a tar file.

I can find the files with something like
Code:
 
for DIR in `find /My/Dirs/ -type d`
   do
   ls -l -rt $DIR |tail -1
done

But how to get that into a tar?? Am i thinking about it all wrong?

BTW i can't just use find as the latest file in the dir could be new or old..
# 2  
Old 04-06-2009
Think i worked it out - for my purposes anyways..

for DIR in `find /MyDir/MyPath -type d`
do
find $DIR -type f -mtime -99 |tail -1 |xargs tar uf /tmp/TMPtar.tar
done
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Emergency UNIX and Linux Support

find all the dirs starting with particular name

Hi Experts, I want to find all the dirs , subdirs on the sever which start with "sr". Can anyone let me know command for the same. find . -type d -name sr* I tried this but it is not working. Thanks, Ajay (4 Replies)
Discussion started by: ajaypatil_am
4 Replies

2. UNIX for Dummies Questions & Answers

Files count mismatch when used with Tar with find

Hi I have used the below steps and found some discrepancies step 1 : find ./ -type f -mtime +7 -name "*.00*" | wc -l = 13519 ( total files ) ( the size of this files is appx : 10GB ) step 2: find ./ -type f -mtime +7 -name "*.00*" | xargs tar zcvf Archieve_7.tar.gz step... (7 Replies)
Discussion started by: rakeshkumar
7 Replies

3. Shell Programming and Scripting

Not correct processing of “\ “ in names of dirs inside shell script (tar command - system backup scr

Hello, Recently, I've started with shell scripting, and decided to write a script for my system backup using tar. When I was dealing with tar execution inside shell script I found this, inside shell we have the following code: tar $TAR_PARAMS $ARCHIVE_FILE $EXCLUDE $BACKUP_STARTwith... (6 Replies)
Discussion started by: ilnar
6 Replies

4. Shell Programming and Scripting

Find *.tar files under all subdirectories

Hi there, I'm new to shell scripting... I've a situation like to find *.tar files under all subdirectories in "/home/abcd" and i used the below, find /opt/lhapp ! -name "temp" | more the above works fine.. Now don't need search few direcotries like "/home/abcd/aaaa",... (15 Replies)
Discussion started by: skcvasanth
15 Replies

5. Shell Programming and Scripting

find files older than and containing then tar.

I'm tring to: find files recursively older than x days that contain dat or DAT then tar them I can find the files older than 90 days containing dat with this: find . -mtime +90 -type f -name "*dat*" -exec tar -cvvfp /some/path/some.tar {} \; but how do I do it case insensitive? ... (3 Replies)
Discussion started by: Ikon
3 Replies

6. Shell Programming and Scripting

Find command and pruning .dirs

I'm sure this has been asked before but I couldn't find it with the search. I have a script that looks for files and then moves to another location for further processing. My problem is I can't seem to prune the .s* directories. It doesn't break anything just wanted a cleaner process. Here... (4 Replies)
Discussion started by: jcalisi
4 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. Shell Programming and Scripting

script find files in two dirs HELP

I have a directory which is /home/mark/files/ , inside this particular I have a bunch of filles (see examples below) TST_SHU_00014460_20090302.txt TST_SHU_00016047_20090302.txt TST_SHU_00007838_20090303.txt TST_SHU_00056485_20090303.txt TST_SHU_00014460_20090303.txt... (2 Replies)
Discussion started by: fierusbentus
2 Replies

9. Shell Programming and Scripting

find and tar 700 files

i have some 700 files of the same pattern differing only in their datestamp. below some of the files. i want to tar them all into one tar file.but the below normal command is telling me "arg list too long" tar -cvf Archive1.tar CurrentCollectorMeterReadBackup* also i tried the below... (6 Replies)
Discussion started by: ali560045
6 Replies

10. UNIX for Dummies Questions & Answers

find a data from several .tar,.gz files

Hi I have a several files with .tar or .gz in a known location. i have files with one of the several files of .tar or .gz text.txt help.pl move.txt how do i write a script to find out those particular files .tar or .gz where that contains the above mentioned files (i.e,... (2 Replies)
Discussion started by: gkrishnag
2 Replies
Login or Register to Ask a Question