The following section covers how to search for a file in Linux by using the find command from a command line. The Command Line Interface or (CLI) in Linux is a text based interface. Sometimes referred to as the terminal, it is where users can interact with the operating system by typing commands. This CLI or terminal provides a flexible and powerful way to control and customize a Linux system. The find command in Linux can be used to search for files and directories on a file system. It works by recursively traversing the file system and matching files based on various criteria such as name, size, or date modified.
Finding a file in Linux from a command line can be both educational and fun and helps you learn to use Linux without relying a graphical user interface.
Table of Contents
Searching for a File in Linux using the Terminal
To search for a file in Linux, you can use the find command. Here are the basic steps:
- Open a terminal window. From Debian or Ubuntu you can use Ctrl+Alt+T
- Type the following command replacing "filename" with the actual name of the file you're searching for, and then press Enter
find -name filename
Note how you can use a wildcard * in the filename to find variations:
How the Find command works to Search File in Linux
The find command will search for a file in Linux and display the path to the file if it's found. If there are multiple files with the same name, the command will display the path to each one. If you use a forward slash before the filename for example: find / -name filename , the find command will search the entire file system, starting from the root directory.
Note that searching the entire file system for a file can take a while, especially if you have a large number of files. So when you can, you should start your search by providing a more specific starting directory.
Narrowing your Linux File Search
If you want to narrow your search for a file to a specific directory or directories under a directory, simply replace the forward slash in the command with the path to the directory you want to search.
For example, the following command specifies to narrow a search for YUMI* to the user named lance.
find /home/lance -name YUMI*
And that's how easy it is to use find to search for a file in Linux.
You can learn about more find command options from the manual by typing man find from an open terminal.