Find Directory In Linux
Linux provides different ways to find directories. Here we will look how to find directories in recursive way.
Find command is popular command to used a lot of different purposes like find file and directory, take backup, copy files. Actually find do not have these abilities it just runs commands over search results like copy and backup.
Find have syntax like below
find LOCATION SEARCH_TERM ACTION
We will search for directory bin in the root file system.
$ find / -name bin
Get Detailed Information
We can get detailed information about found directories by using -ls parameter for the find command.
$ find / -name bin -ls
Here results will list size of the directory permission of the directory, owner , last change date etc.
Only List Directories
Upto now we have search for all files and directories. We can search for only directories by providing type parameter with directory specifier.
$ find / -name bin -ls -type d
Locate command is 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 database we need root privileges.
$ sudo updatedb
We will search for files and directories ends with /bin . In this example we will use regex option of the locate to specify end of line.
$ locate --regex /bin$