[comp.unix.questions] find command

mchinni@pica.army.mil (Michael J. Chinni, SMCAR-CCS-E) (11/28/89)

I was reading an article in a magazine, and the article was talking about the
find command. It mentioned as an example:	find / -depth -print

Now I have RTFM (both on BSD-based systems and SysV-based system) and I can find
no option -depth, furthermore, when I try the example I get:
find: bad option < -depth >

What does this option mean ?

/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
			    Michael J. Chinni
      Chief Scientist, Simulation Techniques and Workplace Automation Team
	 US Army Armament Research, Development, and Engineering Center
 User to skeleton sitting at cobweb   () Picatinny Arsenal, New Jersey  
    and dust covered workstation      () ARPA: mchinni@pica.army.mil
      "System been down long?"        () UUCP: ...!uunet!pica.army.mil!mchinni
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

klee@chico.pa.dec.com (Ken Lee) (11/28/89)

In article <21544@adm.BRL.MIL>, mchinni@pica.army.mil (Michael J.
Chinni, SMCAR-CCS-E) writes:
> Now I have RTFM (both on BSD-based systems and SysV-based system) and
I can find
> no option -depth, furthermore, when I try the example I get:
> find: bad option < -depth >
> 
> What does this option mean ?

The -depth option is found on some older versions of find.  It caused
find to try to search deep before searching wide.  As far as I know, it
was never documented, although it sometimes worked.

Ken Lee
DEC Western Software Laboratory, Palo Alto, Calif.
Internet: klee@decwrl.dec.com
uucp: uunet!decwrl!klee

gwyn@smoke.BRL.MIL (Doug Gwyn) (11/28/89)

In article <21544@adm.BRL.MIL> mchinni@pica.army.mil (Michael J. Chinni, SMCAR-CCS-E) writes:
>Now I have RTFM (both on BSD-based systems and SysV-based system) and I can find
>no option -depth, furthermore, when I try the example I get:
>find: bad option < -depth >
>What does this option mean ?

-depth is a standard option in the System V version of "find".
It tells "find" to perform a depth-first traversal of the file
hierarchy.  This may be important, for example, if you type
	find . -depth -print | chmod -rwx
since without the -depth it will be impossible to access or
even find the names of files in subdirectories in order to
chmod them.

cpcahil@virtech.uucp (Conor P. Cahill) (11/28/89)

In article <21544@adm.BRL.MIL>, mchinni@pica.army.mil (Michael J. Chinni, SMCAR-CCS-E) writes:
> I was reading an article in a magazine, and the article was talking about the
> find command. It mentioned as an example:	find / -depth -print
> 
> Now I have RTFM (both on BSD-based systems and SysV-based system) and
> I can find no option -depth, furthermore, when I try the example I get:
> find: bad option < -depth >

The "-depth" option to find, where it is supported, tells find to visit 
all files in the directory before visiting the directory itself.  This is
needed for the following scenario:

	Directory A exists and has files in it.  

		Normal Find -print	Find -depth -print
		A			A/file1
		A/file1 		A/file2...
		A/file2...		A

		Note that the directory itself (A) is listed last.

	I only have read access to A.
	I am not a super user.
	I want to restore a backup of A.


If the backup was made with standard find (i.e. "-depth" not specified) then
my cpio backup will have the directory on the tape before the files within
the directory.  The directory will be created and set to read-only and I 
will then be unable to restore the files.

If the -depth is specified the directory will be created, but with my ownership
and standard modes when the files are restored and then the modes and ownership
of the directory will be modified to match those on the tape.


-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+

cpcahil@virtech.uucp (Conor P. Cahill) (11/28/89)

In article <2168@bacchus.dec.com>, klee@chico.pa.dec.com (Ken Lee) writes:
> 
> The -depth option is found on some older versions of find.  It caused
> find to try to search deep before searching wide.  As far as I know, it
> was never documented, although it sometimes worked.

It is present AND  documented in System V Release 3.0+.
-- 
+-----------------------------------------------------------------------+
| Conor P. Cahill     uunet!virtech!cpcahil      	703-430-9247	!
| Virtual Technologies Inc.,    P. O. Box 876,   Sterling, VA 22170     |
+-----------------------------------------------------------------------+

drears@pica.army.mil (Dennis G. Rears (FSAC)) (11/28/89)

Mike:

   You write:

>I was reading an article in a magazine, and the article was talking
>about the
>find command. It mentioned as an example:       find / -depth -print
>
>Now I have RTFM (both on BSD-based systems and SysV-based system) and
>I can fi!
>no option -depth, furthermore, when I try the example I get:
>find: bad option < -depth >
>
>What does this option mean ?


  From the SUNOS manual pages:

     -depth    Always true; performs  descent  of  the  directory
               hierarchy  so  that all entries in a directory are
               acted on before the directory itself.  This can be
               useful  when find is used with cpio(1) to transfer
               files that are contained  in  directories  without
               write permission.

Dennis

P.S.  Give me a call and I will give you an account on caesar or
augustus if you want to check it out.

skwu@boulder.Colorado.EDU (WU SHI-KUEI) (11/29/89)

From the AT&T System V, Release 3.1 manual page for 'find', dated 4/87:

"-depth	Always true; causes descent of directory hierarchy to be done so
	that all entries in a directory are acted on before the directory
	itself.  This can be useful when 'find' is used with 'cpio(1)' to
	transfer files that are contained in directories without write
	permission."

battan@qtc.UUCP (Jim Battan) (11/29/89)

>In article <21544@adm.BRL.MIL>, mchinni@pica.army.mil asks about find(1).

Please be aware there's a bug in the SunOS version of find(1).  It's
known by bug id #1008718 and is scheduled to be fixed in 4.1.  Here's the
bug report I filed on Feb 18 1988:

Description:
        find doesn't use the -name option when using -depth.

Repeat-By:
        mkdir a
        cd a
        touch b c
        mkdir d
        touch d/e
        find . ! -name . -print         # gives what it should
        find . -depth ! -name . -print  # still prints "."!!
-- 
Jim Battan     {uunet!sequent,sun!nosun}!qtc!battan    +1 503 626 3081
Quantitative Technology Corporation (QTC)
8700 SW Creekside Place, Suite D  Beaverton, OR  97005

donlash@uncle.UUCP (Donald Lashomb) (11/30/89)

In article <21544@adm.BRL.MIL> mchinni@pica.army.mil (Michael J. Chinni, SMCAR-CCS-E) writes:
>I was reading an article in a magazine, and the article was talking about the
>find command. It mentioned as an example:	find / -depth -print
>
>Now I have RTFM (both on BSD-based systems and SysV-based system) and I can find
>no option -depth, furthermore, when I try the example I get:
>find: bad option < -depth >
>
>What does this option mean ?

Gee, it's in my manual ( AT&T unix-pc ):

	-depth	Always true.  Must begin the expression. Forces a*depth-first
		search: find does not apply the expression to a directory
		until it has applied the expression to all the files in the
		directory.  This is useful with cpio; see example in cpio(1).
		If the example were done without -depth, the modification
		dates on the copied directories would not match their
		originals.

The example from cpio(1) manual page:

	find . -depth -print | cpio -pdl newdir

Hope this helps,
Don

envbvs@epb2.lbl.gov (Brian V. Smith) (12/01/89)

In article <616@uncle.UUCP>, donlash@uncle.UUCP (Donald Lashomb) writes:
< In article <21544@adm.BRL.MIL> mchinni@pica.army.mil (Michael J.
Chinni, SMCAR-CCS-E) writes:
< >I was reading an article in a magazine, and the article was talking
about the
< >find command. It mentioned as an example:	find / -depth -print
< >
< >Now I have RTFM (both on BSD-based systems and SysV-based system) and
I can find
< >no option -depth, furthermore, when I try the example I get:
< >find: bad option < -depth >
< >
< >What does this option mean ?
< 
< Gee, it's in my manual ( AT&T unix-pc ):
< 
< 	-depth	Always true.  Must begin the expression. Forces a*depth-first
<                search...

It seems as though the Ultrix and SunOs find ALWAYS use a *depth-first*
search and there is no option to do a *breadth-first* search.

Anyone out there know if it is possible to do a breadth-first search with find
under Ultrix or SunOs?  I presume BSD is the same.

_____________________________________
Brian V. Smith    (bvsmith@lbl.gov)
Lawrence Berkeley Laboratory
I don't speak for LBL, these non-opinions are all mine.

gsf@ulysses.homer.nj.att.com (Glenn Fowler[drew]) (12/01/89)

In article <4343@helios.ee.lbl.gov>, envbvs@epb2.lbl.gov (Brian V. Smith) writes:
> It seems as though the Ultrix and SunOs find ALWAYS use a *depth-first*
> search and there is no option to do a *breadth-first* search.
> 
> Anyone out there know if it is possible to do a breadth-first search with find
> under Ultrix or SunOs?  I presume BSD is the same.

the -depth option is mis-named - BSD and ATT find always use depth-first-search
by default find does a pre-order DFS - a directory is seen before its children
-depth (when available) turns on a post-order DFS - a directory is seen
after its children have been processed

	$ find . -print		# pre-order
	.
	./first-child
	...
	./last-child

	$find . -depth -print	# post-order
	./first-child
	...
	./last-child
	.

just think of -depth as -post
a breadth-first directory traversal would be resource intensive
-- 
Glenn Fowler    (201)-582-2195    AT&T Bell Laboratories, Murray Hill, NJ
uucp: {att,decvax,ucbvax}!ulysses!gsf       internet: gsf@ulysses.att.com

envbvs@epb2.lbl.gov (Brian V. Smith) (12/02/89)

In article <12446@ulysses.homer.nj.att.com>,
gsf@ulysses.homer.nj.att.com (Glenn Fowler[drew]) writes:
< 
< the -depth option is mis-named - BSD and ATT find always use
depth-first-search
< by default find does a pre-order DFS - a directory is seen before its
children
< -depth (when available) turns on a post-order DFS - a directory is seen
< after its children have been processed
< 
< ...[deleted]
<
< just think of -depth as -post
< a breadth-first directory traversal would be resource intensive

However, there *ISN'T* a -depth option in Ultrix/SunOs/BSD find, so I guess
it isn't possible to do a post-order DFS search.

_____________________________________
Brian V. Smith    (bvsmith@lbl.gov)
Lawrence Berkeley Laboratory
I don't speak for LBL, these non-opinions are all mine.

paul@unhtel.uucp (Paul S. Sawyer) (12/03/89)

The -depth option IS on my Sys V Rel 2, and it is documented.
The -local and -mount options are also there, and are NOT documented!

Sometimes you have to RBTFM (Read Beyond The Fine Manual  B-).
                                  ======

-- 
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Paul S. Sawyer              uunet!unh!unhtel!paul     paul@unhtel.UUCP
UNH Telecommunications        attmail!psawyer       p_sawyer@UNHH.BITNET
Durham, NH  03824-3523      VOX: 603-862-3262         FAX: 603-862-2030

guy@auspex.auspex.com (Guy Harris) (12/08/89)

>However, there *ISN'T* a -depth option in Ultrix/SunOs/BSD find, so I guess
>it isn't possible to do a post-order DFS search.

Err, umm, while Ultrix "find" *might* be a derivative purely of BSD
"find", SunOS "find" hasn't been so since SunOS 3.2; since 3.2, it's
been derived from both BSD's and S5's "find", and *does* have the
"-depth" option.  The Ultrix one might well be so derived also....