The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
problem with shell script execution anju Shell Programming and Scripting 2 05-07-2008 10:50 PM
Problem with find and tar venu_nbk UNIX for Dummies Questions & Answers 2 11-20-2006 07:41 AM
problem with find braindrain Shell Programming and Scripting 2 03-29-2006 09:33 AM
Problem with `find ...` Cameron Shell Programming and Scripting 4 08-10-2005 04:24 AM
Another Find Problem sethkor Shell Programming and Scripting 6 02-24-2005 04:56 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-22-2002
Registered User
 

Join Date: Dec 2001
Posts: 29
Question Find & tar execution problem

I'm trying to set up a stanard sh script that will find all the files that have been changed within the last day and then tar them up.

I think the command line should be something like :


find /home/bob -atime +0 -exec \ tar cvf /home/bob/files.tar {}\;

Help please ...

Thanx
Reply With Quote
Forum Sponsor
  #2  
Old 05-22-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,658
There are a few problems here. First -atime is access time. You want -mtime which is modification time. Next the +0 is going to exclude all the files you want and pick up the rest. "find /home/bob -mtime -1" will give you alist of files modified less than a day ago. But you will also get directories as well as files. "-type f" will take care of that. And finally, you don't want a seperate run of tar for each file...you want to run tar just once.

tar cvf /home/bob/files.tar `find /home/bob -mtime -1 -type f`

will do it. But this assumes that you have enought space on your command line to handle all of the files in question. If you "cd /home/bob" first and use "." instead of "/home/bob" in the find command, you will shorten the length of the list and defer the problem. And having the output file in your home directory is dangerous. If you remove yesterday's before you run the new command you should be ok. But if files.tar gets added to the list, you're in trouble. Putting it in /tmp or /var/tmp while the command is running might be safer.

So my final answer...
cd /home/bob
tar cvf /var/tmp/files.tar `find . -mtime -1 -type f`
mv /var/tmp/files.tar .
Reply With Quote
  #3  
Old 05-22-2002
Registered User
 

Join Date: Dec 2001
Posts: 29
Thanks for that. Problem though when i type the tar command I get an error :

tar : find . -mtime -1 -type f: no such file or directory.

Thoughts please.

########### PLease ignore had ' instead of ` in line #############

Thanx
Reply With Quote
  #4  
Old 05-24-2002
Registered User
 

Join Date: Dec 2001
Posts: 29
Just to complicate matters I want to refine the search to include files that are less than 1 day old and older than 2 hours. Is it possible to search by hours old rather than days.

Thanx

Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0