Why "find dirname -type d" does not work without trailing slash

I am using ksh version M-11/16/88f.

I have run into a strange behavior with Find command. When I use the command without the trailing slash in the directory name, it returns nothing. When I add the trailing slash, it recurses through the directory and list all the subdirectories.

find /tdd/general/performance -- This doesn't work
find /tdd/general/performance/ -- This works.

For other folders, it makes no difference but for this particular folder it does provide any results without the trailing slash.

Can someone please enlighten me as why this is happening. Thank you in advance for the help.

Subhash.

1 Like

@sssccc,
Could you provide the output of ls -l /tdd/general using the markdown code tags, please.

I guess /tdd/general/performance is a reference: a symbolic link or an automount point.

For a symbolic link you can use
find -H /tdd/general/performance
The -H follows a symlink in the given start directory.

An automount behavior is implementation-specific.
Regarding the Linux autofs, I have seen that a first access to a bare directory name returns the unmounted/arbitrary attributes but then fosters the mount; a subsequent access returns the attributes of the mounted filesystem.
In Solaris an access to a bare directory name immediately mounts then returns the attributes.
A trailing / ensures a directory; this always fosters an early mount.

2 Likes

Please see below the actual output. I had shortened the directory in original post to simplify.

/td/elm/general/general1/elmreptr/Performance>ls -l
total 707
drwxr-s--- 3 pelm elmreptr 16384 Aug 1 10:49 BLoan/
drwxr-s--- 7 pelm elmreptr 4096 Jun 15 2021 HELOC/
drwxr-s--- 2 pelm elmreptr 4096 Jun 15 2021 LGD/
drwxr-s--- 2 pelm elmreptr 131072 Aug 3 19:26 LOC/
drwxr-s--- 3 pelm elmreptr 131072 Aug 5 11:37 Loan/
drwxr-s--- 3 pelm elmreptr 32768 Aug 1 10:55 Mortgage/
drwxr-s--- 4 pelm elmreptr 4096 Jun 15 2021 ODP/
drwxr-s--- 2 pelm elmreptr 16384 Aug 2 09:21 SBB/
drwxr-s---

I tried the -H switch. It lists all the files. I only need directories.

this is NOT what was asked.
I asked for:

just add -type d

Is this better ?
/td/elm/general/general1/elmmodlr/chos3f7/usersas/cclist>ls -l /td/elm/general/general1/elmreptr/Performance
lrwxrwxrwx 1 pelm elmreptr 31 Jun 16 2021 /td/elm/general/general1/elmreptr/Performance@ -> /td/dr/elm/elmreptr/Performance/
/td/elm/general/general1/elmmodlr/chos3f7/usersas/cclist>

not exactly what I asked, but good enough.
As @MadeInGermany mentioned here, this directory is a link.
Hence, follow (pun intended) what's been suggested.

That worked. Thanks for your help.

Thanks. It worked with -H -type d.

Just for my future knowledge, what exactly you meant by markdown code tags. I still didn't do it right ?

In order to properly format the posts, one needs to use the "markdown code tags" outlined here in the forum welcome page.
This is done to ease the reading of the posts, and (among others) to distinguish the free-form posts' text AND the code/data sample.

E.g. to format data/code samples enclose it in the triple-backticks (```) like so

```
here comes my data sample
```
that will result in (when posted):

 here comes my data sample

Read the provide link above to get a better handle on what markdown code tags are and/or what's available.

Thanks for asking for the clarification!

2 Likes

Thanks a lot for the detailed explanation. Highly appreciated. Now I know for next time. :smiley: :+1:

1 Like

This topic was automatically closed 300 days after the last reply. New replies are no longer allowed.