FactorPad
Build a Better Process

Linux find Command Summary with Examples

Linux find allows you to search for files within directories.
  1. Purpose - Learn what find is for and how to find help.
  2. Options - Review a few common options and examples.
  3. Examples - Walk through code examples with find.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 23, 2021
In this tutorial on Linux find, 30 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / find-command.html


An ad-free and cookie-free website.


Examples of the Linux find Command

Beginner

Learn to find files within directories at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux find Command Summary with Examples (3:22)

Video Script

The Command and Why You Need It

Our thirtieth word, or command to memorize is find from our category Help.

find allows you to search for files within directories.

Common Linux apropos Options
-options description
--help Print help screen
-name Find files with a specific name or expression

Recall from the previous video, we searched through command titles and descriptions, now we'll search for any type of file.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The find command has many options, and arguments include where you want to search, operations you want to perform, and finally an expression of what you're looking for. The capabilities of the find command are vast, so we'll look at a few simple cases.

Like most commands, help is available with double-dash --help. The -name option offers the ability to search by file name or an expression using wildcards. I'm reluctant to detail other options here, so at this point let's be content with finding files.

So why is find an important command? Well, its capabilities are extensive, meaning you can use it to simply find a file or to take other actions on those files. And now you know how to do that.

Demonstration

Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go, let's start with a find --help and scan that syntax.

$ find --help 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: operators (decreasing precedence; -and is implicit where no others are given): ( EXPR ) ! EXPR -not EXPR EXPR1 -a EXPR2 EXPR1 -and EXPR2 EXPR1 -o EXPR2 EXPR1 -or EXPR2 EXPR1 , EXPR2 positional options (always true): -daystart -follow -regextype normal options (always true, specified before other expressions): -depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf --version -xdev -ignore_readdir_race -noignore_readdir_race tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N -cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME -ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN -links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE -nouser -nogroup -path PATTERN -perm [+-]MODE -regex PATTERN -readable -writable -executable -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N -used N -user NAME -xtype [bcdpfls] actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit -exec COMMAND ; -exec COMMAND {} + -ok COMMAND ; -execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ; Report (and track progress on fixing) bugs via the findutils bug-reporting page at http://savannah.gnu.org/ or, if you have no web access, by sending email to <bug-findutils@gnu.org>.

It gets very very complex, so I suggest reviewing it later.

Next, let's go with find in the current directory using a dot . then -name and the title like this 'video11.txt'.

$ clear $ pwd /home/paul $ find . -name 'video11.txt' ./video11.txt

Okay, good.

And last, let's broaden the search using a wildcard. Typing find -name 'video1*.txt'.

$ find . -name 'video1*.txt' ./video11.txt ./video16.txt ./video19.txt

Again, I'm reluctant to go any deeper at this point given the short window of time here.

A Final Tip

Okay now you know how to use find. And you know the syntax for commands, options and arguments.

One last tip about the find command. The man page (man find) has guidance on how to locate and take actions on a file at the same time. I suggest looking at that.

Okay, thanks for visiting today. I hope this was a helpful introduction to the find command.


Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:


What's Next?

Click below to subscribe to an extraordinarily helpful YouTube Channel. For updates, try out our no-spam email list and @factorpad on Twitter.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / find-command.html


linux find command
find linux
linux find
unix find
linux find wildcards
linux find file recursive
linux search for file
find regex
linux find file
find command syntax
linux find summary
linux find options
linux find tutorial
linux find file by name
find exec
man find
linux find directory
linux find example
linux find recursive

A newly-updated free resource. Connect and refer a friend today.