![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| 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 !! |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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... |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
thank you!
That worked beautifully. |
|||
| Google The UNIX and Linux Forums |