[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question on the find command on Linux

From: Bob Proulx
Subject: Re: Question on the find command on Linux
Date: Fri, 21 Nov 2003 19:48:52 -0700
User-agent: Mutt/1.3.28i

address@hidden wrote:
> Is it  possible , with the find command on linux, to avoid the recursively
> directory hierarchy ?

Find is not a textutil command.  Find has its own mailing list.  But I
think I can answer your question anyway.

> So, i would, for example, remove the file "*.bat" in a directory , but not
> in the recursive directory
> My structure directory is :
> /my_dir/
> /my_dir/recurse_dir/
> this command works, but all the sub directorys are concerned
> => find /my_dir  -name "*.bat"  -exec rm {} \;

Find is recusive by nature.  For your example you probably just want
to use 'rm' directly.

  rm *.bat

But 'find' can control the recursion depth.  These next two options
are probably what you are looking for.

 - Option: -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.

 - Option: -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.

You probably wanted to use:

  find /my_dir -maxdepth 1 -name "*.bat"  -exec rm {} \;

Using find with xargs is more efficient.

  find /my_dir -maxdepth 1 -name "*.bat" -print0 | xargs -r0 rm


reply via email to

[Prev in Thread] Current Thread [Next in Thread]