How To Find Directory In Linux? – POFTUT

How To Find Directory In Linux?

Linux provides different ways to find directories. Here we will look at how to find directories in a recursive way. In this tutorial, we will use commands like  find and locate.

Find Directories and Files with find Command

Find command is popular command to used a lot of different purposes like find file and directory, take a backup, copy files. Actually find do not have these abilities it just runs commands over search results like copy and backup.

Syntax

  • LOCATION is the path or location we will search in
  • SEARCH_TERM is the term which is the file or directory name we want to search
  • ACTION is optional which can take actions like print, delete, rename in the search results

We will search for directory bin in the root file system.

Find Command

Find Command

Get Detailed Information about The Directories and Files

We can get detailed information about found directories by using -ls parameter for the find command.

Get Detailed Information

Get Detailed Information

Here results will list the size of the directory permission of the directory, owner, last change date, etc.

Only List Directories

Up to now, we have searched for all files and directories. We can search for only directories by providing type parameter with directory specifier.

Only List Directories

Only List Directories

Locate

Locate command is a non-interactive alternative to find command. Also, locate have restricted capabilities. Advantage of the locate is that it is fast because locate use database to search. Manually a database for file and directories is created. Manually this database is updated. Search is done directly in this database. Database is located at /var/lib/mlocate/mlocate.db.

We will update our database to search with locate. To update the locate database we need root privileges.

LEARN MORE  Linux Lsof Command Tutorial With Examples

We will search for files and directories ends with /bin . In this example, we will use the regex option of the locate to specify the end of the line.

Locate

Locate

Leave a Reply

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

Enjoy this blog? Please spread the word :)