1

ls - list directory contents

empty_dir# ls -al
total 0
drwxr-xr-x. 2 root root   6 Dec 31 09:49 .
dr-xr-x---. 6 root root 284 Dec 31 09:49 ..

find - search for files in a directory hierarchy

empty_dir# find
.
Share a link to this question
CC BY-SA 4.0
2
  • @A.B Perhaps I should change the Title - it seems incorrect. They are not name-inode maps are they? Would be good to know what they are really called. Your first point is a good one as find is intended to navigate the tree in forward order only? Dec 31 '19 at 10:27
  • @A.B The crux of the question is that ls lists directory contents - so . and .. are contained within a directory but I don"t think they really are else find would list them too. Find only lists . but this is not really contained in the directory its just a notation for the current directory. A satisfactory answer would point to some formal specification which describes this. Dec 31 '19 at 10:34
1

find has to deliberately exclude . and ..

It has to avoid descending into them, as it would do for other directories returned by readdir().

Rather than show the directories . and .. but not show any of their contents, it excludes them entirely.

This is the desired behaviour, for example if you used find -exec touch \{\} \;. Users would not wish this command to affect .. (the parent directory).

A satisfactory answer would point to some formal specification which describes this.

Arguably, POSIX is trying to document this. I don't understand well enough to rely on it as a formal spec. But the bolded sentence below suggests that it does not "encounter" . and ...

The find utility shall recursively descend the directory hierarchy from each file specified by path, evaluating a Boolean expression composed of the primaries described in the OPERANDS section for each file encountered. Each path operand shall be evaluated unaltered as it was provided, including all trailing characters; all pathnames for other files encountered in the hierarchy shall consist of the concatenation of the current path operand, a if the current path operand did not end in one, and the filename relative to the path operand. The relative portion shall contain no dot or dot-dot components, no trailing characters, and only single characters between pathname components.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html

Share a link to this answer
CC BY-SA 4.0
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.