Enter your email address:

Delivered by FeedBurner

How to find files, using command line (locate)


StumbleUpon Toolbar

Continuing reviewing some of my old posts, I found this one Examples of find command, now I want to show you a faster and easier way to find files.

We are going to use the commands updatedb and locate

updatedb

This command will update the database of the files in a given file system, with no arguments, it will read from / to all file system structure looking for files and archiving the data in the database, located in Debian (/var/cache/locate/locatedb).

There is an option for those using NFS (like me) that you can use to include your NFS file system in the database.

--netpaths=’path1 path2...’

So you can enter a command like this:

sudo updatedb --netpaths=/media/nfs_drive

Now that you have your database updated lets find files.

locate

You just need to enter:

locate filename

and the file named filename will be showed, example:

locate apt-cacher -b

The output is:

/etc/apache2/conf.d/apt-cacher.conf
/etc/apt-cacher
/etc/apt-cacher/apt-cacher.conf
/etc/cron.daily/apt-cacher
/etc/default/apt-cacher
/etc/init.d/apt-cacher
/etc/logrotate.d/apt-cacher
/etc/rc0.d/K20apt-cacher
/etc/rc1.d/K20apt-cacher
/etc/rc2.d/K20apt-cacher
/etc/rc3.d/S20apt-cacher
/etc/rc4.d/S20apt-cacher
/etc/rc5.d/S20apt-cacher
/etc/rc6.d/K20apt-cacher
/etc/rcS.d/S20apt-cacher
/usr/lib/cgi-bin/apt-cacher
/usr/sbin/apt-cacher
/usr/share/apt-cacher
/usr/share/apt-cacher/apt-cacher
/usr/share/apt-cacher/apt-cacher-cleanup.pl
/usr/share/apt-cacher/apt-cacher-format-transition.pl
/usr/share/apt-cacher/apt-cacher-import.pl
/usr/share/apt-cacher/apt-cacher-lib-cs.pl
/usr/share/apt-cacher/apt-cacher-lib.pl
/usr/share/apt-cacher/apt-cacher.pl
/usr/share/apt-cacher/apt-cacher-precache.pl
/usr/share/apt-cacher/apt-cacher-report.pl
/usr/share/apt-cacher/apt-proxy-to-apt-cacher
/usr/share/doc/apt-cacher
/usr/share/man/man1/apt-cacher.1.gz
/var/cache/apt-cacher
/var/cache/apt-cacher/headers/apt-cacher_1.6.1_all.deb
/var/cache/apt-cacher/packages/apt-cacher_1.6.1_all.deb
/var/cache/apt-cacher/private/apt-cacher_1.6.1_all.deb.complete
/var/lib/dpkg/info/apt-cacher.conffiles
/var/lib/dpkg/info/apt-cacher.list
/var/lib/dpkg/info/apt-cacher.md5sums
/var/lib/dpkg/info/apt-cacher.postinst
/var/lib/dpkg/info/apt-cacher.postrm
/var/lib/dpkg/info/apt-cacher.prerm
/var/log/apt-cacher
/var/run/apt-cacher.pid

With the option -b only shows the files where the final part of the name matches the given file name, otherwise, it will show you the full content of the directory /etc/apt-cacher.

Trackback URL for this post:

http://www.go2linux.org/trackback/498
from fsdaily.com on Sat, 05/24/2008 - 07:18

This story has been submitted to fsdaily.com! If you think this story should be read by the free software community, come vote it up and discuss it here:

http://www.fsdaily.com/EndUser/How_to_find_files_using_command_line_loca...

StumbleUpon Toolbar

 If you like this article, subscribe to our full rss

If this article was somehow useful for you, you can leave something in the tip's jar

Please post your question in our forum and use comments only to leave your comments about the article, thanks.

I use locate all the time -

I use locate all the time - I even made a small GUI for it...
http://www.bin-co.com/ruby/tk/locater/

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options

Captcha
This question is for testing whether you are a human visitor and to prevent automated spam submissions.

This site is proudly hosted at Bluefur Hosting