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
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"
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
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
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
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
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
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
locate -b '\mydata'

The Third Method Is With The Ack Tool
How to install?
Now ack has to be installed on your distribution so <a href="https://lateweb.info/linux-search-for-string-in-folders-and-files-with-ack/">here is a guide</a> on how to do it.
<h5>How to use ack?</h5>
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
ack string-to-search
cd /var/lib
ack name

02 - To find how many files contain the string you are searching use
ack -f | wc -l
2331
03 - To search for instances of our pattern surrounded by word boundaries use -w
ack -w string-to-search

04 - Use <strong>-c</strong> to get detailed information about the string you are searching for
ack -c string-tosearch
Doxyfile:8
Makefile:2
uncrustify.cfg:1
.travis.yml:2
neovim.rb:0
vim-license.txt:52

05 - Search for file type like css or python or txt
ack string-to-search --css

Bonus Search tools
<table><thead><tr><th><strong>Search Tools</strong></th></tr></thead><tbody><tr><td><strong><a href="https://github.com/BurntSushi/ripgrep">ripgrep</a></strong></td><td>Recursively search directories for a regex pattern</td></tr><tr><td><strong><a href="https://github.com/junegunn/fzf">fzf</a></strong></td><td>Command-line fuzzy finder for your shell</td></tr><tr><td><strong><a href="https://github.com/peco/peco">peco</a></strong></td><td>Interactive filtering tool</td></tr><tr><td><strong><a href="https://github.com/cantino/mcfly">McFly</a></strong></td><td>Navigate through your shell history</td></tr><tr><td><strong><a href="https://launchpad.net/catfish-search">catfish</a></strong></td><td>Versatile search GUI powered by locate and find</td></tr><tr><td><strong><a href="http://cboxdoerfer.github.io/fsearch/">FSearch</a></strong></td><td>Fast file search utility based on GTK+3</td></tr><tr><td><strong><a href="https://github.com/DoTheEvo/ANGRYsearch">ANGRYsearch</a></strong></td><td>Like FSearch, a search tool inspired by Everything Search Engine</td></tr></tbody></table>
Here is a quick video on the tutorial
https://youtu.be/ryC3Ssrelzc
We hope you enjoyed this <a href="https://lateweb.info/category/linux/">article</a>. if that is so please rate this page with the stars bellow and subscribe to our <a href="https://www.youtube.com/channel/UCh7Q9uaAt5-Z2lCZXX3OsvQ">YouTube channel</a>.