0

I'm writing a small script to count all the files in a directory, and have a solution as follows:

find . -maxdepth 1 -type f | wc -l

I understand everything in this solution so far, except for the period after find. Why is it there, and what does it do? Why does the solution not work without it? E.g. why can't I just write:

find -maxdepth 1 -type f | wc -l
Rommel
  • 3
  • 3
  • 1
    It means the current working directory, or folder in Windows term. The latter works with *GNU* `find(1)` but not on `*BSD`'s and others. – Jetchisel Sep 10 '21 at 08:30
  • See the `find` man-page: _find [-H] [-L] [-P] [-D debugopts] [-Olevel] [starting-point...] [expression]_ : The arguments preceeding the expression (i.e. `-type f` in your case) are the _starting points_, i.e. the directories where the search should start. – user1934428 Sep 10 '21 at 11:21

2 Answers2

2

After find command, first thing you should give are the directories (you may specify more than one) where the search will be made. . indicates the current working directory.

-type f : Look for files, not directories.
-maxdepth 1: Descent at most 1 level in the directory tree.
| : Redirect output to another command
wc -l : Print the number of lines in a file

Muhteva
  • 2,729
  • 2
  • 9
  • 21
0

In each folder are 2 links "." and ".."
"." - current folder.
".." - parent folder

Taron Qalashyan
  • 660
  • 4
  • 8