How-to

Find a File on Linux, the Fast Way

Different questions need different tools. A name you half remember, a config a package installed, a command on the PATH: each has a one-line answer.

Which tool answers which question?

QuestionToolExample
Where is a file with this name, anywhere?plocateplocate php.ini
Where is it, right now, in this tree?find or fdfind /etc -name '*.conf'
Which program runs when I type a command?type, whichtype -a python3
Which package owns this file?dpkg -S, rpm -qfdpkg -S /usr/sbin/nginx
Which files contain this text?grep -rgrep -rl 'listen 443' /etc/nginx

How do I search by name instantly?

Use a locate database. plocate is the current implementation on Debian 13 and Ubuntu, and mlocate or plocate on Enterprise Linux:

apt install plocate          # dnf install plocate where available, or mlocate
updatedb                     # build the index now; a daily timer keeps it fresh
plocate -i 'pool.d'          # case-insensitive substring match
plocate -r '/sshd_config$'   # regular expression match

Answers come back in milliseconds because they come from an index, not the disk. The catch: files created since the last updatedb run are missing, and deleted ones may still appear. For anything recent, use find.

How do I search a tree live?

find / -xdev -name 'wp-config.php' 2>/dev/null
find /srv -iname '*invoice*.pdf' -mmin -120

-xdev keeps find on one file system, skipping /proc and mounted drives; 2>/dev/null hides permission errors. -iname ignores case and -mmin -120 limits results to files changed in the last two hours. The full set of tests and actions is in The find command guide.

fd is a faster, friendlier alternative that respects .gitignore and uses regex by default. On Debian and Ubuntu install fd-find; the command is fdfind there:

fdfind -e log -t f . /var/www

Where is a command installed?

type -a php
which -a node
command -v rsync
readlink -f "$(command -v python3)"

type -a lists every match on the PATH, plus aliases and shell functions, which explains "I installed a new version but the old one runs". readlink -f follows symlinks to the real file, useful with alternatives systems that point /usr/bin/python3 somewhere else. whereis also finds manual pages and sources for a command.

Which package put this file here?

dpkg -S /etc/php/8.3/fpm/php.ini     # Ubuntu, Debian
rpm -qf /etc/nginx/nginx.conf         # Rocky Linux, AlmaLinux, CentOS Stream
dpkg -L openssh-server | grep config  # every file of a package
rpm -ql postgresql-server | grep bin

This answers where a configuration came from and whether an update will touch it. For files not installed yet, apt-file search or dnf provides tell you which package would provide them: dnf provides '*/bin/dig' returns bind-utils.

How do I find big files filling the disk?

du -xh / 2>/dev/null | sort -h | tail -20
find /var -xdev -type f -size +1G -printf '%s\t%p\n' | sort -n | tail

The first lists the largest folders; the second the largest single files under /var, where logs, caches and databases usually grow. ncdu offers the same in an interactive browser and is worth installing on every machine. On two-drive models, check the second drive too; it often becomes the dumping ground for backups.

What about deleted files still using space?

A process can keep a deleted file open, so the space is not released until it closes. lsof +L1 lists such files with the process holding them; restarting that service frees the space. A log rotated without signaling the writing process is the classic cause.

How do I find files changed recently?

After an incident or a deploy, list what changed: find /etc /srv -xdev -type f -mmin -60 -ls shows files modified in the last hour with sizes and owners, which quickly reveals an edited config or an unexpected upload.

Keep Reading

The find command guide

A thorough guide to find: tests for name, type, size, time and owner, logical operators, pruning, actions, -exec forms and safe deletion.

Open

The grep command

grep from basics to power use: case, whole words, line numbers, context, recursion, regex flavors, only-matching output and speed tips.

Open

Format a disk on Linux

Turn the blank second NVMe drive into usable space: identify it, partition with GPT, choose ext4 or XFS, mount by UUID and keep TRIM on.

Open

List all cron jobs

Find every scheduled job on a machine: user crontabs, system files, cron.d, periodic folders, anacron and systemd timers.

Open

FAQ

Quick Answers

plocate, which searches an index and answers in milliseconds. Run updatedb first for recent files.

Run find / -xdev -name 'pattern' 2>/dev/null.

Use type -a or command -v; readlink -f shows the real file behind symlinks.

dpkg -S on Debian and Ubuntu, rpm -qf on Rocky Linux and AlmaLinux.

Use find with -size +1G, or du sorted by size, or the interactive ncdu.