find Filters
find -name matches by name. But find can filter by other properties too, most
usefully by type and size.
Filter by type: -type
The -type option says whether you want files or directories:
| Condition | Matches |
|---|---|
-type f | regular files |
-type d | directories |
find . -type d
That lists every folder under .. To find only files:
find . -type f -name "*.log"
This reads as: under ., find things that are files and whose name ends in
.log. Multiple conditions are simply listed one after another: find requires
all of them to match.
Filter by size: -size
The -size option matches files by how big they are:
| Example | Matches |
|---|---|
-size +1k | bigger than 1 kilobyte |
-size -1k | smaller than 1 kilobyte |
-size +1M | bigger than 1 megabyte |
A + means "more than", a - means "less than". The letter is the unit (k, M,
G).
find . -type f -size +1k
That finds every file larger than 1 KB.
Mission: Station Directory Scan
The chief engineer needs a structural overview of the station folder before reorganising the file system, and the text notes gathered in one place.
- List only the directories inside
station. - List only the
.txtfiles insidestation(files, not folders). - Gather the text notes you found: create a folder called
txt-indexand copystation/notes.txtandstation/bay/manifest.txtinto it.
Expected result
You see the directory paths, then the .txt file paths, and the txt-index folder holds copies of both text notes.