8

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?

2
  • Have you tried the locate command? Just checking, because this question sounds too easy... May 24, 2011 at 15:25
  • @nick: I have tried that now but it wasn't working as I expected, see my comment to the posted answer.
    – Jonas
    May 24, 2011 at 15:48

4 Answers 4

12

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.).

10
  • 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 using locate contrib or locate *contrib*.
    – Jonas
    May 24, 2011 at 15:45
  • 1
    so, use locate postgresql, after having updated the db (sudo updatedb) if required. Remember, it is not updated instantly after each filesystem modification. The contrib keyword is not a so happy choice.
    – enzotib
    May 24, 2011 at 16:08
  • @enzotib: locate postgresql doesn't work well for me, I only get /etc/bash_completion.d/postgresql as result.
    – Jonas
    May 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.
    – Jonas
    May 24, 2011 at 16:20
7

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".

1

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.
0

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

3
  • @Jonas: also, update your question, in particular the title. If not pertinent, i will delete my answer.
    – enzotib
    May 24, 2011 at 15:59
  • @enzotib: No, the question is how I search for files (not only in this situation).
    – Jonas
    May 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.
    – Jonas
    May 24, 2011 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .