Important Commands to search Files and Directories in Linux.

0
24
Search FIles and Directories in Linux

Important Commands to search files and directories in Linux

To search Files and Directories in Linux, there are two important commands.

They are

  1. # locate
  2. # find

Locate Command:

  • Locate command always looks at the locate database and not in a specific location. The data of the locate is stored in /var/lib/mlocate/mlocate.db file.
  • If the data is not updated in the locate database or the locate database is available or locate database is deleted, we cannot locate the files and directories.
  • # updatedb is the command to update the locate database.
  • locate database cannot find the newly created files and directories.
  • It is not recommended to use on production servers because it impacts on the performance of the servers.
  • So, to overcome this problem we normally use # find command on production servers.

# updatedb (to update the locate database)

# locate (to search the specified file or directory)

Search FIles and Directories in Linux

Related Articles:

What is a Link File in Linux ? and its types.

What is the File system and Types of File System in Linux?

What is the difference between Shadow files and Passwd files?

Find Command:

  • Find Command is one of the important commands in Linux to search files and Directories.
  • It is also one of the widely used commands in Linux and also very easy to use.
  • Find command required a specific location. Without a specific location, we cannot find the files or directories.

Use the below command, to search the files in a Specific Location.

# find <location><options><file or directory>   (to find the specific file or directory).

The options are,

-name —–> search files and directories

-prem —–> search for permissions

-size —–> search for sizes

-user —–> search for the owner

-uid —–> search for files/directories of uid)

-gid —–> search for files/directories of gid)

-group —–> search for group owner

-empty —–> search for empty files

-amin —–> search for access time

-mmin —–> ”   ”

-cmin —–> ”    ”

-atime —–> search for access day (access day, minutes, hrs, …etc)

-mtime —–> search for modify day (change the content)

-ctime —–> search for change day (permissions, …..etc)

This is the full information about the Find and Locate Commands to search files and Directories in Linux.

LEAVE A REPLY

Please enter your comment!
Please enter your name here