tags:

views:

39

answers:

1

find and find -depth -print

what is difference ?

+1  A: 

-depth simply means that the contents of a directory are processed before the the directory itself:

pax> find /tmp
/tmp
/tmp/.X11-unix
/tmp/pax
/tmp/sort444444
/tmp/sort544444
/tmp/sort644444
/tmp/sort744444
/tmp/XWin.log

pax> find /tmp -depth
/tmp/.X11-unix
/tmp/pax
/tmp/sort444444
/tmp/sort544444
/tmp/sort644444
/tmp/sort744444
/tmp/XWin.log
/tmp

-print means that each item is printed to standard output. This is often the default on system where you don't specify an action but I've seen some that default to doing nothing (not very useful in my opinion).

You're probably better off (if your system supports them) explicitly using -print0 if you're going to be piping the output to xargs (and use xargs -0). This will remove problems of spaces in filenames.

paxdiablo
actually i am using this in cpio like find . | cpio -o | cpio -id , so i want cpio to create dirs if does not exist
soField
so does it matter to use depth option in order to cpio to create dirs or can i use straigthforward find
soField
Actually if you're _creating_ directories, you probably don't want `-depth`. You want to create the directories first, not the files within them. In any case, I think `cpio -d` will create directories anyway so it may not matter.
paxdiablo