Welcome back, aspiring cyberwarriors!
For many aspiring hackers, the biggest barrier is mastering the Linux command line (CLI). This series is designed specifically for those who want to become pentesters or ethical hackers but need to build a strong foundation in CLI Linux.
Aspiring hackers new to Linux often struggle with a common challenge: how to locate files, binaries, directories, and configuration files within the system. While AI can now generate commands on demand, relying on it is not a professional approach. Skilled hackers know how to find what they need themselves. With just a handful of commands and techniques, you can significantly reduce frustration and make navigating the Linux command line far more intuitive.
This tutorial will teach you how to locate files in Linux efficiently using the command line. Let’s get rolling!
locate
Linux provides several tools for finding applications, commands, files, and other items from the command line. One of the simplest and most convenient is locate. By running locate followed by a keyword, the system quickly searches through its indexed file database and returns every matching path.
kali> locate filename

Sometimes what locate finds is overwhelming, too much information. In addition, if you just created a file, it may not appear in this list as locate uses a database that is updated once a day. A file you created today usually won’t appear in that database until tomorrow, unless you explicitly update the database using the command below.
kali> sudo updatedb
whereis
If you know you’re searching for a binary (similar to an executable in Windows), Linux offers a dedicated command for that: whereis. This command not only returns the location of the binary, but also provides the path to its manual page.
kali> whereis wifite

As shown above, whereis returned only the wifite binary and its compressed manual page, instead of listing every file containing the word wifite like locate did.
which
The which command is even more specific, as it only returns the locations of binaries that are included in the system’s PATH variable.
kali> which wifite

As shown above, which found a single binary within the directories listed in the PATH variable. We’ll explore the PATH variable in more detail in a later tutorial, but for now it’s enough to know that PATH defines where the operating system looks for executable commands you type into the terminal. At a minimum, this typically includes /usr/bin.
find
The find command is the most powerful and flexible of the search utilities. Unlike tools such as locate, find can begin searching from any specified directory and filter results using many different parameters. It can search by filename, by when a file was created or modified, by who owns it, what group it belongs to, its permissions, its size, and many other attributes.
The basic syntax for find is:
kali> find
For example, if I wanted to search for a file named apache2 starting from the root directory /, I would enter:
kali> sudo find / -type f -name apache2
In this command, / specifies the directory where the search will begin, -type f tells find to look specifically for regular files, and -name apache2 instructs it to search for files with the name apache2.

As shown above, the find command began at the root of the filesystem and searched through every directory to locate files named apache2. Because of this, it returned multiple results, but the process can be slow since find must traverse the entire directory tree. If we only want to search within the /etc directory, we can limit the scope and speed up the search. By starting the search from /etc, find will look only in that directory and its subdirectories for files named apache2. The command would be:
kali > sudo find /etc -type f -name apache2

As shown above, the more targeted search completed much faster and only returned apache2 files located within /etc and its subdirectories. It’s important to remember that, unlike other search tools such as locate, find only returns exact matches. This means that a file like apache2.conf would not appear when searching for apache2 alone. To overcome this limitation, we can use wildcards such as *, ?, or []. For instance, if we want to search the /etc directory for any file that begins with apache2 and includes any extension (such as apache2.conf), we could use a wildcard in our command like this:
kali > sudo find /etc -type f -name ‘apache2.*’

Note that I had to use the single quotes around the name I was searching for with the wildcard.
grep
Very often, when working in the command line, we need to search through output for a specific keyword. This is where the grep command becomes useful. grep acts as a filter, allowing us to search text for matching patterns. It is commonly used in combination with other commands by piping one command’s output into another.
We’ll cover piping more thoroughly in a later tutorial, but for now it’s enough to understand that both Linux and Windows allow us to take the output of one command and feed it directly into another. This process is called piping, and it uses the | symbol (usually located above the Enter key on the keyboard). For example, if I want to view all services running on my Linux system, I can use the ps command with the aux options like this:
kali > ps aux

As you can see, the command returns a complete list of all services currently running on the system. However, if we want to locate a specific service within that long list, we can pipe the output from ps into grep and search for a keyword. For example, to check whether the apache2 service is running, we could enter:
kali > ps aux | grep apache2

As shown above, grep filtered out all other services and displayed only those containing apache2 in their name, saving time and sparing us from scanning through the entire list manually.
Summary
Linux is a necessary operating system for hackers, and mastering it is essential for a successful career in cybersecurity.
In this article, we explored several ways to locate files, binaries, and directories on a Linux system using command-line tools such as locate, whereis, which, find, and grep. Understanding these utilities will help you navigate the filesystem more confidently and efficiently.
For more information on using Linux for hacking, check out the book “Linux Basics for Hackers” on Amazon or visit our training center.
Source: HackersArise
Source Link: https://hackers-arise.com/linux-basics-for-hackers-part-02-finding-stuff/