CyberStars

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:

ConditionMatches
-type fregular files
-type ddirectories
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:

ExampleMatches
-size +1kbigger than 1 kilobyte
-size -1ksmaller than 1 kilobyte
-size +1Mbigger 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 is reorganising the station folder and needs an overview first:

  1. Every folder inside station, and nothing that is a file.
  2. Every text note in station, the files ending in .txt, wherever they sit.
  3. All those notes gathered in a new txt-index folder, each under its own name.

Expected result

You see the folder paths, then the paths of the text notes, and txt-index holds a copy of each note.