Start Searching In Linux Like A Pro ( 10 examples + Bonus Tip )

User Avatar
👤 admin
🔴 Admin
✍️ The most important thing in the world is to not be alone.
⏳ Last active: 15 Apr 2025 at 16:01
📅 Created: 29 Apr 2021 at 19:06
👀 Viewed: 18 times
✉️ Send Email

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.

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:

Image

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:

Image

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

Image

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

Image

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

Image

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

Search for exactly only specified criteria

locate -b '\mydata'


![Image](uploads/2021/04/image-156.png)

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

Basic usage

ack string-to-search

Example:

cd /var/lib

ack name


![Image](uploads/2021/04/image-71.png)

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


03 - To search for instances of our pattern surrounded by word boundaries use -w

Surrounded by

ack -w string-to-search


![Image](uploads/2021/04/image-72.png)

04 - Use <strong>-c</strong> 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


![Image](uploads/2021/04/image-73.png)

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



![Image](uploads/2021/04/image-74.png)

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&nbsp;<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&nbsp;<a href="https://www.youtube.com/channel/UCh7Q9uaAt5-Z2lCZXX3OsvQ">YouTube channel</a>.
If you want to comment: Login or Register