How do I search for a file or directory in Ubuntu Server?

47,711

Solution 1

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

Solution 2

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

Solution 3

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.
Share:
47,711

Related videos on Youtube

Jonas
Author by

Jonas

Updated on September 18, 2022

Comments

  • Jonas
    Jonas over 1 year

    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?

    • Jose Silva
      Jose Silva almost 13 years
      Have you tried the locate command? Just checking, because this question sounds too easy...
    • Jonas
      Jonas almost 13 years
      @nick: I have tried that now but it wasn't working as I expected, see my comment to the posted answer.
  • Jonas
    Jonas almost 13 years
    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*.
  • enzotib
    enzotib almost 13 years
    @Jonas: also, update your question, in particular the title. If not pertinent, i will delete my answer.
  • Jonas
    Jonas almost 13 years
    @enzotib: No, the question is how I search for files (not only in this situation).
  • Jonas
    Jonas almost 13 years
    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.
  • enzotib
    enzotib almost 13 years
    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.
  • Jonas
    Jonas almost 13 years
    @enzotib: locate postgresql doesn't work well for me, I only get /etc/bash_completion.d/postgresql as result.
  • Jose Silva
    Jose Silva almost 13 years
    @Jonas looking at the file list, it is located in /usr/share/postgresql/8.4/contrib/. Try "locate contrib/"
  • Jonas
    Jonas almost 13 years
    @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.
  • enzotib
    enzotib almost 13 years
    @Jonas: as I said, have you update the locate db with sudo updatedb?
  • Jose Silva
    Jose Silva almost 13 years
    @Jonas Yeah, the dir might not have been indexed yet.
  • Jonas
    Jonas almost 13 years
    @enzotib: Thanks, now does locate postgresql work, but how often am I supposed to run sudo updatedb? I installed PostgreSQL a long time ago.
  • enzotib
    enzotib almost 13 years
    @Jonas: it is updated daily (in /etc/cron.daily/mlocate). You can update it manually when you need.
  • Jonas
    Jonas almost 13 years
    @enzotib: but it was many days since I installed PostgreSQL.