1

find . and find . -depth -print

What is the difference?

1
  • 2
    belongs to superuser.com, btw, try man find Commented Jun 9, 2010 at 8:08

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

3 Comments

actually i am using this in cpio like find . | cpio -o | cpio -id , so i want cpio to create dirs if does not exist
so does it matter to use depth option in order to cpio to create dirs or can i use straigthforward find
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.