It's often that I need to locate the path to files and directories in Ubuntu Server. Are there any good way to search for files or directories in the filesystem by name?
4 Answers
You name it: locate
!
locate
is a program installed by default that let you search for files/dirs by name, into its database updated with a cron job.
Go through the man page to see other interesting options, like regex search.
Moreover, you can use find
to search on the current content of the filesystem (not on a database), with a full set of complicated options, that let you refine your search also based on metadata (permissions, modification time, etc.).
-
I installed a package to PostgreSQL using
apt-get install postgresql-contrib-8.4
but I don't know where it is installed and I can't find it usinglocate contrib
orlocate *contrib*
.– JonasMay 24, 2011 at 15:45 -
1so, use
locate postgresql
, after having updated the db (sudo updatedb
) if required. Remember, it is not updated instantly after each filesystem modification. Thecontrib
keyword is not a so happy choice.– enzotibMay 24, 2011 at 16:08 -
@enzotib:
locate postgresql
doesn't work well for me, I only get/etc/bash_completion.d/postgresql
as result.– JonasMay 24, 2011 at 16:10 -
@Jonas looking at the file list, it is located in /usr/share/postgresql/8.4/contrib/. Try "locate contrib/" May 24, 2011 at 16:18
-
@nick: Thanks, that path seem to be correct, but I can't find it using
locate contrib/
it just give me a list of other directories but none of them are related to PostgreSQL.– JonasMay 24, 2011 at 16:20
The command find / -name "name-to-search-for"
seem to work fine. A good thing was to add a *
in the end or at the beginning of the name.
E.g. find / -name "postgresql*"
list files and directories that starts with "postgresql".
If you are installing and want to know what files you install... you can do that immediately following an install by doing the following:
touch marker
find <directorypath> -newer marker
There are some situations in which you will get results other than the newly installed applications(s):
- if Firefox or another browser is running there may be updated files
- if Virtualbox or other virtualization guest is running its virtual disk file may have been altered.
This method should work with installs from .deb files or scripted installs.
NOTE:
- Do not use this from the 'root' directory as there are many system files that are updated frequently.
According to your comments, you are not looking for specific filenames but for files that belong to a package. To see which files are associated with your installed package just type:
dpkg -L postgresql-contrib-8.4
-
@Jonas: also, update your question, in particular the title. If not pertinent, i will delete my answer.– enzotibMay 24, 2011 at 15:59
-
@enzotib: No, the question is how I search for files (not only in this situation).– JonasMay 24, 2011 at 16:02
-
Thanks for this command, but I wan't to learn how to search for files by name, so this command only help me in this specific situation.– JonasMay 24, 2011 at 16:05