Find command takes long

Hi,

I am trying to search for a Directory called "mont" under a directory path "/opt/app/var/dumps"

Although "mont" is in the very parent directory called "dumps" i.e "/opt/app/var/dumps/mont" and it can never be inside any Sub-Directory of "dumps"; my below find command which also checks for permissions on the directory "mont" however takes more than 2 hrs.

find /opt/app/var/dumps -type d -name mont -perm 600 

Is there a way we can only consider the directory structure in the search while excluding the files.

How can we quicker the search result ?

No! How do you suppose find determines which files it finds in a file hierarchy search are directories as opposed to some other type of file? It reads all of the directory entries in each directory it finds and then uses stat() (or a similar system call) to determine the type of that file. The find utility has no way to magically ignore non-directory files before it determines whether or not that file is a directory.

However, if find does encounter any directory that is mode 600, it won't be able to examine any files in or under that directory.

If you know that the pathname to the directory you want to process is /opt/app/var/dumps/mont , why are you using find instead of something like:

ls -ld /opt/app/var/dumps/mont

?

Here is another approach without using find :-

#!/bin/ksh

dir="/opt/app/var/dumps/mont"

os=$(uname)

if [ -d "$dir" ]
then
    
        [ "$os" = "Linux" ] && mod=$( stat --printf="%a" "$dir" ) || mod=$( perl -e'printf "%o",(stat shift)[2] & 07777' "$dir" )

        [ "$mod" = "600" ] && print "$dir"
fi

The reason i am using find instead ls ls -ld is becoz along with making sure mont exists under dump folder i should be able to check permissions on mont folder

find /opt/app/var/dumps/mont -prune -type d -perm 600 2>/dev/null

But I share the feeling there might be a better approach - if we knew the context.

And if I use ls -ld for files that do not exist and for files that do exist, as in:

$ ls -ld /opt/app/var/dumps/mont
ls: /opt/app/var/dumps/mont: No such file or directory
$ ls -ld .
drwxr-xr-x@ 211 dwc  staff  7174 Jul 12 10:10 .
$ 

it clearly shows me that /opt/app/var/dumps/mont does not exist on my machine and clearly shows me that . does exist and shows me its mode. On the other hand, if I run the command:

$ find . -type d -name pdf -perm 600
$ 

I only know that there is no directory named pdf with mode 600 in the file hierarchy rooted in my current directory, while the command:

$ ls -ld pdf
drwxr-xr-x@ 14 dwc  staff  476 Aug 25  2013 pdf
$ 

clearly shows me that there is a directory named pdf in my current directory and that it has mode 755.

And, all of the above commands (except the find command) take less than a second.

So, less than a second to get the exact information you want versus more than two hours to maybe get the information you want. Tell me again why:

ls -ld /opt/app/var/dumps/mont

is a bad choice here to find out if there is a file named /opt/app/var/dumps/mont and, if there is, what type of file it is and what mode it has???