• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Tuesday, June 24, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

Ways to Use ‘find’ Command to Search Directories More Efficiently

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
129
VIEWS
Share on FacebookShare on Twitter

This tutorial will take you through the different ways of finding a directory in Linux. As you may already know, in Linux everything is a file including directories. And one of the common things a Linux user will do within the command line is searching for a file or a directory.

There are several different means and utilities used for searching for files on the command line such as find, locate and which. However, the last utility (which) is only used for locating a command.

For the scope of this tutorial, we will mainly focus on the find utility, which searches files on a live Linux filesystem and is more efficient and reliable as compared to locate.

The downside of locate is that it reads one or more databases created by updatedb, it does not search through a live filesystem. In addition, it does not as well offer flexibility regarding where to search from (starting point).

Below is the syntax for running locate command:

# locate [option] [search-pattern]

To demonstrate the disadvantage of locate, let us assume we are searching for a directory named pkg in the current working directory.

Note: In the command below, the option --basename or -b tells locate to only match the file (directory) basename (which is exactly pkg) but not the path (/path/to/pkg). Where / is a globbing character, it disables the implicit replacement of pkg by *pkg*.

$ locate --basename '/pkg'
Ways to Use ‘find’ Command to Search Directories More Efficiently

Find Directory Using locate Command

As you can see from the command output above, locate will search beginning from the root (/) directory, that is why other directories with the same name are matched.

Therefore, to deal with this issue, use find by following the simplified syntax below:

$ find starting-point options [expression]

Let us look at a few examples.

To search for the same directory (pkg) above, within the current working directory, run the following command, where the -name flag reads the expression which in this case is the directory basename.

$ find . -name "pkg"

If you encounter “Permission denied” errors, use sudo command like so:

$ sudo find . -name "pkg"
Ways to Use ‘find’ Command to Search Directories More Efficiently

Search a Directory Using find Command

You can prevent find from searching for other file types except directories by using -type flag to specify the type of file (in the command below d means directory) as follows:

$ sudo find . -type d -name "pkg"

Furthermore, if you wish to list the directory in a long listing format, employ the action switch -ls:

$ sudo find . -type d -name "pkg" -ls
Ways to Use ‘find’ Command to Search Directories More Efficiently

Find and List Directory

Next, the option -iname will enable a case insensitive search:

$ sudo find . -type d -iname "pkg" 
$ sudo find . -type d -iname "PKG" 
Ways to Use ‘find’ Command to Search Directories More Efficiently

Find Directory with Case Sensitive

To find more interesting and advanced usage information, read the man pages of find and locate.

$ man find
$ man locate

As a last remark, the find command is more reliable and efficient for searching files ( or directories) in a Linux system when weighed against the locate command.

In the same way as before, do not forget to send us your feedback or questions via the comment section below. Lastly, always remain connected to Tecmint.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

fdupes – A Command Line Tool to Find and Delete Duplicate Files in Linux

Next Post

Newsroom – A Modern CLI to Get Your Favorite News in Linux

Next Post

Newsroom – A Modern CLI to Get Your Favorite News in Linux

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In