The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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-08-2008 01:50 AM
Problem with find and tar venu_nbk UNIX for Dummies Questions & Answers 2 11-20-2006 10:41 AM
problem with find braindrain Shell Programming and Scripting 2 03-29-2006 12:33 PM
Problem with `find ...` Cameron Shell Programming and Scripting 4 08-10-2005 07:24 AM
Another Find Problem sethkor Shell Programming and Scripting 6 02-24-2005 07:56 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-22-2002
ianf ianf is offline
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
  #2 (permalink)  
Old 05-22-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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 .
  #3 (permalink)  
Old 05-22-2002
ianf ianf is offline
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
  #4 (permalink)  
Old 05-24-2002
ianf ianf is offline
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

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 08:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0