Linux Basics: Finding Files with find
When you remember a filename but not its location, find can search a directory and its subdirectories. These examples use GNU find on Debian and Ubuntu.
Prepare a small directory
Run mktemp -d, then use cd to enter the path it prints. Inside that temporary directory, create a few practice files:
mkdir -p notes/archive
touch notes/todo.txt notes/IDEAS.TXT notes/archive/old.txtSearch by name
find notes -type f -name '*.txt'
find notes -type f -iname '*.txt'notes is the starting directory. -type f limits matches to regular files. -name matches the filename and is case-sensitive, so it does not match IDEAS.TXT here. Use -iname when capitalization should not matter.
Keep the wildcard pattern in quotes. This lets find interpret * instead of having your shell expand it before the search starts.
Limit the search
find notes -maxdepth 1 -type f
find notes -type d-maxdepth 1 checks the starting directory and its immediate children. It does not descend into archive, so old.txt is excluded. -type d selects directories, including the starting directory itself when it matches.
To search elsewhere, replace notes with a specific path, such as ~/Documents if that directory exists. Starting in the smallest likely directory keeps results manageable and avoids unrelated permission errors.
To list only text files directly inside notes, combine the options:
find notes -maxdepth 1 -type f -name '*.txt'notes/todo.txtThese examples only list matching paths. They do not open, move, or delete anything.
Reference
Acknowledgements
This post was created with assistance from AI.
Linux Basics — lesson 6 of 25. Series index
Previous: Reading and Searching Text Files · Next: Pipes and Output Redirection