Restricting a Find search to the current directory only | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    


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 !!

Restricting a Find search to the current directory only

UNIX for Dummies Questions & Answers


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 05-11-2012
daveu7 daveu7 is offline
Registered User
 
Join Date: Mar 2012
Last Activity: 6 February 2013, 10:17 AM EST
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Restricting a Find search to the current directory only

Hi All,

I am trying to delete file (with a mtime older than 2 days) from the current directory ONLY using:


Code:
find . -daystart -maxdepth 1 -mtime 2 -exec rm {} \;

but this doesn't seem to work it is still find files in subdirectories which I don't want to delete.

Please can anyone offer any advise about the use of the -maxdepth or do I need to use mindepth.

The man dialogue on the Find command states the following - what exactly does the phrase to the command line arguments mean ?

Man Find states:


Code:
 -maxdepth levels
              Descend at most levels (a non-negative integer) levels of directories below the command line arguments.  -maxdepth 0
               means only apply the tests and actions to the command line arguments.

       -mindepth levels
              Do not apply any tests or actions at levels less than levels (a non-negative integer).  -mindepth 1 means process all files  except  the
              command line arguments.

Many thanks for your help

Last edited by Scrutinizer; 05-11-2012 at 08:15 AM.. Reason: code tags
Sponsored Links
    #2  
Old 05-11-2012
Ygor's Avatar
Ygor Ygor is offline Forum Advisor  
Advisor
 
Join Date: Oct 2003
Last Activity: 10 November 2014, 6:18 PM EST
Location: 54.23, -4.53
Posts: 1,801
Thanks: 1
Thanked 112 Times in 98 Posts
http://www.unix.com/answers-frequent...d-command.html
Sponsored Links
    #3  
Old 05-11-2012
methyl methyl is offline Forum Advisor  
Advisor
 
Join Date: Mar 2008
Last Activity: 18 April 2014, 5:13 AM EDT
Posts: 6,396
Thanks: 287
Thanked 673 Times in 642 Posts
Please post what Operating System and version you have. There is much variation in the find command.

Have you tried:

Code:
-maxdepth 0

And:

Code:
-type f

Also, while you are testing ... just echo the command:

Code:
find . -daystart -maxdepth 0 -type f -mtime 2 -exec echo rm {} \;

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
C Program to search and read all named pipes in current directory natwickley Homework & Coursework Questions 2 12-03-2011 01:44 AM
Restricting zip to current directory only phudgens Shell Programming and Scripting 5 10-13-2009 05:35 PM
non recursive search in the current directory only puppala Shell Programming and Scripting 9 08-21-2008 02:03 PM
Restrict my search to current directory. sachin.gangadha UNIX for Dummies Questions & Answers 7 12-01-2007 12:37 PM
Question about Restricting Search path of FIND to current directory super_duper_guy UNIX for Dummies Questions & Answers 2 10-17-2005 10:10 AM



All times are GMT -4. The time now is 03:53 PM.