The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
"find command" to find the files in the current directories but not in the "subdir" swamymns Shell Programming and Scripting 9 07-22-2008 08:23 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-19-2007 10:52 PM
grep to find content in between curly braces, "{" and "}," keshav_rk Shell Programming and Scripting 4 08-09-2007 07:14 PM
Unix masters please help newbie on "find" command white_raven0 UNIX for Dummies Questions & Answers 2 09-26-2005 09:54 PM
Commands on Digital Unix equivalent to for "top" and "sar" on other Unix flavour sameerdes UNIX for Advanced & Expert Users 1 08-28-2002 05:41 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 08-01-2006
Registered User
 

Join Date: Jul 2006
Posts: 12
Unix "find" question

I want to find all files in a particular directory that are over 45 days old and belong to the user that ran the script

so, setting $userid to the output of `whoami` I used this command:

find . -mtime +45 -user $userid -print | xargs rm

Which works fine when it finds results. However, when I run it the second time it appears to ignore the userid and gives me only the files over 45 days old? What am I doing wrong here?

Thank you in advance...
Reply With Quote
Forum Sponsor
  #2  
Old 08-01-2006
Registered User
 

Join Date: Feb 2006
Location: Schenectady, NY
Posts: 130
When I ran a similar command with userid not defined, I received this message:

# find . -mtime +14 -user $userid -print | xargs ls
find: cannot find -print name


It then goes on to give me an listing of everything in the directory. I can get a similar result with

# cat /dev/null | xargs ls

So it appears that find is exiting on an error and closing its stdout. xarg then processess everything in the directory. I'd recommend replacing the xargs(1) pipeline with the find(1) "-exec" expression and quoting $userid. Also, it can't hurt to add a "-type f" expression to limit the search to files only.

find . -type f -mtime +45 -user "$userid" -print -exec rm {} \;

Last edited by hegemaro; 08-01-2006 at 10:36 AM.
Reply With Quote
  #3  
Old 08-01-2006
Registered User
 

Join Date: Jul 2006
Posts: 12
thank you!

That worked beautifully.
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 03:54 AM.


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