Understand the importance of -depth option in find command.

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Understand the importance of -depth option in find command.
# 1  
Old 08-27-2014
Question Understand the importance of -depth option in find command.

Hi All,

Can you please help me in understanding the importance of -depth of find.

I am trying to execute below code.
find . -mtime +5  -name  "*"  -depth -exec ls -l {} \;

But it is throwing below error.
find: warning: you have specified the -depth option after a non-option argument -mtime, but options are not positional
(-depth affects tests specified before it as well as those specified after it). 
Please specify options before other arguments.

From the error I can understand that there is problem with the position of -depth

But I just want to know the concept in this.

Kindly help me with your suggestions.

Last edited by rbatte1; 08-27-2014 at 01:24 PM..
# 2  
Old 08-27-2014
It is not an error it is just a warning. Probably it will go away if you specify
find . -depth -mtime ....

This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 08-27-2014
Referring to the find manpage, -depth is an option while -mtime and -name are tests.
This section (also from the find manpage) describes the "problem with the position of -depth" pretty good, imho. Hope this helps.
       All options always return true.   Except  for  -daystart,  -follow  and
       -regextype,  the  options  affect  all tests, including tests specified
       before the option.  This is because the options are processed when  the
       command  line  is parsed, while the tests don't do anything until files
       are examined.  The -daystart, -follow and -regextype options  are  dif‐
       ferent  in  this respect, and have an effect only on tests which appear
       later in the command line.  Therefore, for clarity, it is best to place
       them  at  the  beginning of the expression.  A warning is issued if you
       don't do this.

These 3 Users Gave Thanks to junior-helper For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Variable inside -name option for find command

Hi, I am not able to get output for find command if there are variables defined inside -name option . Please check below example 1) ###VARIABLES DEFINED process="fast" temperature="125c" voltage="0p935v" 2) I don't get output for below find command find -L <PATH> -type f \( -name... (2 Replies)
Discussion started by: gujrathinr
2 Replies

2. UNIX for Dummies Questions & Answers

cmd find: exclude directory when using option -depth

hello, i want to use "-depth" in command "find" and want to exclude a directory. the find command should work in HP-UX and Linux. i see in the find man page: -prune If -depth is not given, true; do not descend the current directory. If -depth is given, false; no effect. -depth... (3 Replies)
Discussion started by: bora99
3 Replies

3. Shell Programming and Scripting

Confusing find command option

Hi, I am a little bit confusing of using find command. Actually, I am planning to delete the files whatever the files are existing in the day before yesterday. So, I am writing the command like this. find . -name "*.txt" -ctime -2 { here I am confusing, if I will use +2 or +1 also I am... (5 Replies)
Discussion started by: nagraju.allam
5 Replies

4. Shell Programming and Scripting

Please suggest me a better option than FIND command

Hi All, Could you please help me in searching files in a better way satisfying the below conditions I want to search files in a path whose access time is more than 5min and less than 60 min and whose Byte size is greater than zero For this, i am using the below command, but it is... (2 Replies)
Discussion started by: sparks
2 Replies

5. Shell Programming and Scripting

complicated exclude option in find command

Hi all, In a directory, I have many video files. Example : As you can see, some of the video files come with a .aspx file (wich means the video is actually being uploaded and not entirely written on the FS) I try to write a bash script that would find all video files in the ... (1 Reply)
Discussion started by: gniagnia
1 Replies

6. HP-UX

Understand option in vparecreate

hi every body i want to know this option what it means vparcreate -g ILM:128:y -g CLM:128:y (2 Replies)
Discussion started by: maxim42
2 Replies

7. Shell Programming and Scripting

daystart option not working in find command

Hi, I am trying to list all the files created / modified today in a directory. With reference to this thread, https://www.unix.com/shell-programming-scripting/20324-capture-all-today-files.html I have used the below command to list all the files modified today. find . -daystart -type f... (8 Replies)
Discussion started by: arunkumarmc
8 Replies

8. Shell Programming and Scripting

help with find command and prune option

Hi I have a directory say mydir and inside it there are many files and subdirectories and also a directory called lost+found owned by root user I want to print all files directories and subdirectorres from my directory using find command except lost+found If i do find . \( -name... (3 Replies)
Discussion started by: xiamin
3 Replies

9. UNIX for Dummies Questions & Answers

help me out with find command , -prune option

Hi , Kindly help me out .:) i want to find only the file t4 in directory t3. i am in dir t . the tree is as follows. if i give, find . o/p is . ./t4 ./t1 ./t1/t2 ./t1/t2/t3 ./t1/t2/t3/t4 ./t1/t2/t4 ./t1/t4 directories are like t/t1/t2/t3 and each directory has file t4. my... (7 Replies)
Discussion started by: bhuvaneshlal
7 Replies

10. UNIX for Advanced & Expert Users

Find command -size option limitation ?

Hi All, I ran code in test environment to find the files more than 1TB given below is a snippet from code: FILE_SYSTEM=/home/arun MAX_FILE_LIMIT=1099511627776 find $FILE_SYSTEM -type f -size +"$MAX_FILE_LIMIT"c -ls -xdev 2>/dev/null | while read fname do echo "File larger than... (3 Replies)
Discussion started by: Arunprasad
3 Replies
Login or Register to Ask a Question

Featured Tech Videos