I am trying to find settings.xml file in my Ubuntu machine. I have no clue where it is, and which directory it is in.

I tried using this -

ls -R | grep settings.xml

But it doesn't show me the full path where it is.. Is there any other command which I need to try that can give me the full path?

  • 4
    Whenever you think the solution is to parse the output of ls, you are almost certainly doing it the wrong way.
    – terdon
    Feb 11 '14 at 0:38

For fast search (but not definitive):

locate -br '^settings.xml$'

From man locate:

   locate  reads  one or more databases prepared by updatedb(8) and writes
   file names matching at least one of the PATTERNs  to  standard  output,
   one per line.

   -b, --basename
          Match  only  the base name against the specified patterns.  This
          is the opposite of --wholename.
   -r, --regexp REGEXP
          Search for a basic regexp REGEXP.  No PATTERNs  are  allowed  if
          this  option  is used, but this option can be specified multiple

The ^ and $ ensure that only files whose name is settings.xml and not files whose names contain settings.xml will be printed.

You may need for the first time to run: updatedb (as root) to update/build the database of locate.

  • @terdon, you surprised me, I have never though about looking to man locate before!!! assuming it just simple search tool. Thank you very much.
    – user.dz
    Feb 11 '14 at 0:46
  • Yes, that was pretty much my reaction the first time I read the man page :)
    – terdon
    Feb 11 '14 at 0:47
  • 4
    it is worth noting the role of updatedb for this command -- locate often fails without that, for me, anyways
    – rm-vanda
    Feb 11 '14 at 0:55
  • @rm-vanda, I've updated the answer to mention updatedb. Thank you.
    – user.dz
    Feb 11 '14 at 1:07
  • 4
    locate '*/settings.xml' is probably more portable among the various different implementations of locate (where available). Feb 26 '16 at 22:23

A slow but steady search through file-system, but Definitive.

find / -xdev -name settings.xml

It will take some time and you may get some permission errors but it will get there. If you've got some more idea where it may be located change the first directory from / to /where/you/guess

  • 4
    Appending 2>/dev/null to the end of the command will suppress all of the error output (by redirecting stderr to the null device). Feb 12 '14 at 18:43
  • 2
    -xdev: Don't descend directories on other filesystems.
    – Pablo A
    May 17 '17 at 13:51


$ locate settings.xml

tree is another good way, if you aren't sure exactly what you're looking for, and it seems to be a bit faster- :

tree -f / | grep settings.xml

Other useful flags: -i on grep will ignore the case, -h for human readable on tree --

-- the man page has a lot of useful options -!

  • 6
    Not a good idea, tree(1) shows an ASCII-art tree of the files, which is then mutilated by grep(1).
    – vonbrand
    Feb 11 '14 at 1:24
  • 1
    Yes, if you're going to use tree, you may as well use find . type -f which will be faster.
    – terdon
    Feb 11 '14 at 1:29

The -la parameters print the long version of ls and the directories as well. ls -la | grep settings.xml

  • 2
    This would still not give you the full path to the given file.
    – Kusalananda
    Apr 30 '19 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.