Script Valley
Linux Basics Complete Course: From Beginner to System Administrator
Module 2: Linux File System and NavigationLesson 2.3

Finding Files in Linux | find, locate, which Commands

find command, locate command, which command, whereis, searching files in Linux

Finding Files in Linux

One of the most powerful capabilities of the Linux terminal is the ability to search for files and directories anywhere on the system quickly and precisely. The find, locate, and which commands are the primary tools for file searching in Linux.

The find Command

The find command is the most powerful and flexible way to search for files. It searches in real time by traversing the file system, so results are always current. The basic syntax is find [path] [options] [expression].

find /home -name "*.txt"
find / -name "sshd_config"
find /var/log -type f -mtime -7
find . -name "*.sh" -executable

The -name option searches by filename. The -type option filters by type: f for regular files, d for directories, l for symbolic links. The -mtime option searches by modification time โ€” -mtime -7 finds files modified in the last 7 days.

Finding by Size and Permissions

The find command can also search by file size using -size and by permissions using -perm. These are especially useful for system auditing and security tasks.

find /home -size +100M
find / -perm 777 -type f

The locate Command

The locate command searches a prebuilt database of file paths instead of scanning the file system in real time. This makes it extremely fast, but the database must be updated with the updatedb command to reflect recent changes. On most systems, updatedb runs automatically as a daily cron job.

locate sshd_config
sudo updatedb
locate "*.conf"

The which and whereis Commands

The which command tells you the full path of an executable command. It searches through the directories listed in your PATH environment variable. The whereis command provides the locations of the binary, source code, and manual page for a given command.

which python3
which bash
whereis ls
whereis nginx

These file-searching Linux commands are essential for diagnosing configuration issues, finding installed binaries, and auditing a system. They are used daily by system administrators and developers alike.

Finding Files in Linux | find, locate, which Commands โ€” Module 2: Linux File System and Navigation โ€” Linux Basics Complete Course: From Beginner to System Administrator โ€” Script Valley โ€” Script Valley