Updated: 11 October 2026 · Applies to: GNU findutils 4.10.0 (Debian 13, AlmaLinux 10.2) and 4.9.0 (Ubuntu 24.04); plocate 1.1.23 (Debian 13), 1.1.22 (AlmaLinux and Rocky Linux 10)
To find a file by name in Linux, run find with the folder to search and the name: find /home -name "notes.txt". Use -iname to ignore upper and lower case, wildcards such as "*report*" for part of a name, and / as the folder to search the whole system. Add 2>/dev/null to hide the Permission denied messages:
find / -name "notes.txt" 2>/dev/null find /home -iname "*report*"
Looking for a word or a setting inside files instead? That is a job for grep: see find files containing text in Linux. All output below comes from a lab folder on Debian 13, Ubuntu 24.04 and AlmaLinux 10.
Find a file by name, step by step
- Pick where to look. The first argument is the starting folder:
.is the current folder,/homeall home folders,/the whole system (the slowest). find searches every subfolder below it. - Give the name.
-name "notes.txt"matches the exact name, and find prints the full path of every match:$ find /home -name "notes.txt" /home/anna/notes.txt /home/anna/projects/site/node_modules/lib/notes.txt
- Ignore case if you are not sure.
-nameis case-sensitive:-name "report.pdf"found nothing in our lab, while-inamefound both files:$ find /home -iname "report*.pdf" /home/anna/report-2026.pdf /home/anna/Report.PDF
- Use wildcards for part of a name.
*matches any number of characters and?exactly one:-name "*report*",-name "backup-2026-??.tar.gz". Always put the pattern in quotes (see the errors below). - Hide the noise. As a normal user, a search of
/printsfind: '/root': Permission deniedfor every folder you cannot read. Add2>/dev/nullto discard those messages, or run the search withsudoto look inside those folders too.
When nothing matches, find prints nothing and still exits with code 0. No output simply means there is no file with that name below the starting folder.
Find files by extension (one or several)
For one extension, use a wildcard. -type f keeps only regular files:
find /var/www -type f -name "*.php" find /home/anna -iname "*.jpg" # also matches .JPG
For several extensions at once, join -name tests with -o (OR) inside escaped brackets:
$ cd /home/anna $ find . -type f \( -name "*.sh" -o -name "*.txt" -o -name "*.c" \) ./notes.txt ./projects/site/app.c ./projects/site/node_modules/lib/notes.txt ./projects/build.sh ./todo.txt
The brackets matter. Without them, -type f only applies to the first name: in our test, find . -type f -name "*.sh" -o -name "*.txt" also listed a directory called old.txt. A regular expression does the same job in one test, but it matches the whole path, which is why it starts with .*:
find . -type f -regextype posix-extended -regex '.*\.(sh|c)$'
Search for a directory (folder) by name
Add -type d to match only directories:
$ find / -type d -name "photos" 2>/dev/null /home/anna/photos $ find /srv -type d -name "*html*" /srv/www/example.com/public_html
-type f matches only files and -type l only symbolic links.
Limit or exclude parts of the search
-maxdepth 1searches the folder itself but not its subfolders:find /home/anna -maxdepth 1 -name "*.txt". Put it straight after the folder.- To skip a folder such as
node_modules,.gitor a backup folder, prune it:find /home/anna -name node_modules -prune -o -name "*.txt" -print. The simpler-not -path "*/node_modules/*"gave the same result in our test, but find still walks through the skipped folder, which is slower on large trees. -xdevkeeps the search on one file system, sofind / -xdev -name os-releasedoes not wander into mounted backup disks or network shares.
Combine the name with size, age or an action
find /srv -name "*.log" -size +10M -exec ls -lh {} + # large logs, with sizes
find /home/anna -name "*.txt" -mtime -7 # changed in the last 7 days
find /home -type f -name "*.txt" | wc -l # count the matches
find /srv -type f -name "*.php" -printf '%p %s bytes\n' # your own output format
In our lab the first line printed -rw-r--r-- 1 root root 12M Oct 10 04:31 /srv/www/example.com/logs/error.log. More on these: find the largest files, find and sort files by modification date, count the files in a directory and delete files with find (always run the search without -delete first).
Faster searches with locate (plocate)
locate looks names up in a database instead of walking the disk, so it answers at once even on a large server. Debian, Ubuntu, AlmaLinux and Rocky Linux package it as plocate:
sudo apt install plocate # Debian and Ubuntu sudo dnf install plocate # AlmaLinux and Rocky Linux sudo updatedb # build the database now locate notes.txt locate -i report.pdf # ignore case locate -c "*.jpg" # only count the matches
The catch: the database is rebuilt once a day (the plocate-updatedb.timer systemd timer on Debian 13 and AlmaLinux 10), so newer files are missing. In our test a file created after updatedb was not found until we ran sudo updatedb again, and before the first run locate stopped with /var/lib/plocate/plocate.db: No such file or directory. Details: install and use the locate command. Other options: fd, a simpler find and command line tools to find files quickly.
Errors you may see
find: paths must precede expression: `todo.txt'followed byfind: possible unquoted pattern after predicate `-name'?: the pattern had no quotes, so the shell replaced*.txtwith the names in the current folder before find saw it. Write-name "*.txt". It is worse when exactly one file in the current folder matches: find then runs without any error but looks only for that one name. In our Ubuntu test, an unquotedfind . -name *.txtsilently missedsub/b.txt.find: '/root': Permission denied: you may not read that folder. Hide the message with2>/dev/nullor search withsudo. find then exits with code 1, even when it found files.find: '/nope': No such file or directory: the starting folder does not exist. Check the path.
File extensions in Linux
Linux does not need file extensions. .txt or .jpg is just part of the name, and whether a file can run depends on its permissions, not on its extension. To see what a file really is, use file, which reads the content. In our test it recognised a PDF saved without an extension and a program renamed to photo.jpg:
$ file /home/anna/invoice /home/anna/photo.jpg /home/anna/invoice: PDF document, version 1.7 /home/anna/photo.jpg: ELF 64-bit LSB pie executable, x86-64, ... (shortened)
To list files that have no extension at all, run find . -type f ! -name "*.*". More: find out file types in Linux.
Find where a command is installed
For programs, find is more than you need: command -v find or which find prints the path that runs (/usr/bin/find), and whereis find also lists its manual pages.
More examples: practical find command examples and use wildcards safely with find, ls, cp, mv and rm.
Ucartz services for this topic
- KVM VPS hosting: NVMe SSD and full root access, with Free Basic Managed Support.
- Unmanaged dedicated servers: full root access and free IPMI KVM, with Free Basic Managed Support.
- Linux server management: hardening, patching, monitoring and automation for Ubuntu, Debian, RHEL and AlmaLinux.
