Now this article is going to be as simple as possible and straight forward as possible. The idea is to help you understand the pure basics in Linux searching. In addition we are going to use several searching tools to help us with this quest.
- How to search with the find command
-> Search for specific extensions
-> Search in subfolders
-> Search by by owner
-> Search by file permissions - How to search using the locate command
-> How to install locate
-> Search for a file
-> Search by exact criteria - How to search using the ack tool
-> Basic usage
-> Find how many files contain string
-> Search for pattern
-> Get detailed information for a string
-> Search by extension - Bonus Search Tools
- Video With Examples
The First Search Method Is With The Find Command:
With the find command you can search a folder for files with a specific extensions. For example we are going to find all our files that contain .html in our home directory:
# How to find files with specific extensions using the find command
cd /home/userprofile/
find -name "*.html"
Code language: PHP (php)
Now lets assume that we have several .html documents in this directory, the output will be something like this:

But if we are in the /home folder we can ask find to search for a name or extension in the subfolders too like in this example:
# Search with find in subfolders
find /home -name index.html
Code language: PHP (php)
The find command is going to search all subfolders in /home directory and find all files that are named index.html:

Another cool way to search with find is by owner and it can be very useful when you need to find all the files for a specific user like in the next example:
# Find files who belong to
find / -user sonik 2> /dev/null
Code language: PHP (php)

Now this one is very good in this next example we are going to search for files witch specific permissions like 777
# Search for files with permissions
find /home/sonik -perm 777
Code language: PHP (php)

The Second Search Method Is Going To Be Using The Locate Command
Install Locate
By default locate may not be installed on your distribution so depending on your distro it has to be installed. In this example we are going to install it in Ubuntu Linux like so:
# Install locate in Ubuntu 21.04 Linux
sudo apt-install locate
#update locate db
sudo updatedb
Code language: CSS (css)
Locate has several alternatives like mlocate and plocate, but we are going to use locate because it’s most popular.
Search for a file with locate
Now locate is going to search in the whole Linux system and the most common and basic search with locate is just locate + files search name like in this example
# Search for a file with locate
locate filename
Code language: PHP (php)

Search for exactly only specified criteria
If you want to find all files or directories that contain exactly and only your search criteria, use the -b
option with the locate command, like in this example:
# Search for exactly only specified criteria
locate -b '\mydata'
Code language: PHP (php)

The Third Method Is With The Ack Tool
How to install?
Now ack has to be installed on your distribution so here is a guide on how to do it.
How to use ack?
If you use ack just typing ack “text” the command will work perfectly fine, but it can give you so much more power. Here are some examples:
01 – Basic usage
# Basic usage
ack string-to-search
# Example:
cd /var/lib
ack name
Code language: PHP (php)

02 – To find how many files contain the string you are searching use
# Find how many files contain string
ack -f | wc -l
# Output
2331
Code language: PHP (php)
03 – To search for instances of our pattern surrounded by word boundaries use -w
# Surrounded by
ack -w string-to-search
Code language: PHP (php)

04 – Use -c to get detailed information about the string you are searching for
# Detailed information about string
ack -c string-tosearch
# Output
Doxyfile:8
Makefile:2
uncrustify.cfg:1
.travis.yml:2
neovim.rb:0
vim-license.txt:52
Code language: CSS (css)

05 – Search for file type like css or python or txt
# Search for file type like css or python or txt
ack string-to-search --css
Code language: PHP (php)

Bonus Search tools
Search Tools | |
---|---|
ripgrep | Recursively search directories for a regex pattern |
fzf | Command-line fuzzy finder for your shell |
peco | Interactive filtering tool |
McFly | Navigate through your shell history |
catfish | Versatile search GUI powered by locate and find |
FSearch | Fast file search utility based on GTK+3 |
ANGRYsearch | Like FSearch, a search tool inspired by Everything Search Engine |