I created a empty directories, and executed the following in the terminal
mael@mael-HP:~/repertoireVide$ mkdir -p a/b/c
mael@mael-HP:~/repertoireVide$ mkdir -p a/a/b
mael@mael-HP:~/repertoireVide$ mkdir -p b/a
mael@mael-HP:~/repertoireVide$ echo "c" > a/c
mael@mael-HP:~/repertoireVide$ echo "c" > c
Tree shows the following mael@mael-HP:~/repertoireVide$ tree
.
├── a
│ ├── a
│ │ └── b
│ ├── b
│ │ └── c
│ └── c
├── b
│ └── a
└── c
7 directories, 2 files
Why does the following find command output this
mael@mael-HP:~/repertoireVide$ find .
.
./a
./a/a
./a/a/b
./a/c
./a/b
./a/b/c
./c
./b
./b/a
Isn't find
only suppose the look for FILES inside the specified directories, as per the man find
:
find - search for files in a directory hierarchy
Why are all the sub-directories listed with the files ?
Thanks.
-
Everything in unix type operating systems is a file. Your keyboard is a file, your hard drive is a file, find itself is a file.jesse_b– jesse_b2019年10月25日 21:16:34 +00:00Commented Oct 25, 2019 at 21:16
-
People saying "files" when they mean only "regular files" are not really POSIX-compliant. :)Kamil Maciorowski– Kamil Maciorowski2019年10月30日 06:41:15 +00:00Commented Oct 30, 2019 at 6:41
1 Answer 1
Directories are files. Find can look for regular-type files using the -type
option:
find . -type f ...
Or for directory type files:
find . -type d ...
-type t
True if the file is of the specified type. Possible file types are as follows:
b block special c character special d directory f regular file l symbolic link p FIFO s socket