Very quick tip for you today, I just see that many of visitors of this block are curious how they can find a directory in Unix – and so here's a command to help you do just that.
Finding directories in Unix
There's nothing better than to employ the find command. As you might remember, among many things, this wonderful tool allows you to search files by their type. Since nearly everything in Unix is a file, this means you can find directories.
Let's take an example: if you wand to find out everything about your MySQL installation, you can have a search across your filesystems to find all the directories called mysql:
Here is how you would find a directory called mysql under /etc directory:
ubuntu# find / -name mysql -type d /var/log/mysql /var/lib/mysql /var/lib/mysql/mysql /etc/mysql /usr/lib/perl5/DBD/mysql /usr/lib/perl5/auto/DBD/mysql /usr/share/mysql
As you can see, there are quite a few directories which belong to MySQL, and you can see from the list that MySQL configuration is most likely to be in /etc/mysql directory.
Narrowing down directory search in Unix
If you search across all your filesystems, it may take too much time. That's why it makes sense to narrow your search using common sense.
For example, if you're looking for a configuration file of some standard package of software, most likely it will be under /etc directory, so you can specify it and greatly reduce the searching time.
In this example, we're narrowing directory search to only those directories that are part of /etc:
ubuntu# find /etc -name mysql -type d /etc/mysql
Singh K says
i have to find the location of the file which is called from the shell i.e the current location of the file where it is kept
can any one help on this?
Rakesh says
To find a file you can use the command as follows –
find . -name "file_name"
the dot "." indicates the current directory.
This will try to find the file within the current directory and it's sub-directories. You can even use the wildcard character , asterix "*", to find files.
Baz says
Awesomly usefull ! thx
Alice says
Thank you