Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Command

Description

find

Code Block
Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]
default path is the current directory; default expression is -print
expression may consist of: operators, options, tests, and actions:
...
EXPRESSION
       The  part  of the command line after the list of starting points is the expression.  This is a
       kind of query specification describing how we match files and what we do
...
  TESTS
    ...
    -name pattern
      Base of file name (the path with the leading directories removed) matches shell pattern pattern.
    ...
    -iname pattern
       Like -name, but the match is case insensitive.
    ...
Info

The find command is naturally recursive.

...

Examples

Info

Find the file named: 20230121.txt

...

Info

Use wildcards to find all files with the postfix .csv:

Lets look at two versions:

Info

With quotes:

Code Block
[intro_to_linux]$ find . -name "*.csv"
./software.csv
./data/2022/Hello.csv
Info

Without quotes:

Code Block
[intro_to_linux]$ find . -iname *.csv
./software.csv
Note

Using or not using quotes across commands is an advanced and confusing subject.

If you do not use quotes, then if you have a file in the current directory ending with .csv, the wildcard is essentially expanded by the shell.

So, if you have a file named say "software.csv" (which we do), the command that gets executed is find . -name software.csv.

This single file is found, and the command stops.

Surrounding the search term with quotes prevents this from happening.

Info

Find any files/folders that contain the string dec. Case-sensitive versus case-insensitive.

...