Locating Lost Files with locate

If you’re looking for a system file—that is, a program or file that is part of the Unix system itself, rather than one of your personal files in your home directory—try locate to find it. You’ll get more results than you can handle, but it’s a quick and easy way to locate system files.

The locate command isn’t available on all Unix systems, but it is worth a try at any rate. See Code Listing 2.13 for locate in action.

Code Listing 2.13. Use locate to find everything— everything—related to most system files.
[jdoe@frazz jdoe]$ locate fortune
/usr/share/man/man6/fortune.6.bz2
/usr/share/doc/fortune-mod-1.0
/usr/share/doc/fortune-mod-1.0/cs
/usr/share/doc/fortune-mod-1.0/cs/
→ HISTORIE
/usr/share/doc/fortune-mod-1.0/cs/LICENSE
/usr/share/doc/fortune-mod-1.0/cs/README
/usr/share/doc/fortune-mod-1.0/fr
/usr/share/doc/fortune-mod-1.0/fr/
→ COPYING.linuxfr
/usr/share/doc/fortune-mod-1.0/fr/
→ COPYING.glp
/usr/share/doc/fortune-mod-1.0/fr/ffr

...

/usr/share/games/fortunes/songs-poems
/usr/share/games/fortunes/sports.dat
/usr/share/games/fortunes/sports
/usr/share/games/fortunes/startrek.dat
/usr/share/games/fortunes/startrek
/usr/share/games/fortunes/translate-me.dat
/usr/share/games/fortunes/translate-me
/usr/share/games/fortunes/wisdom.dat
/usr/share/games/fortunes/wisdom
/usr/share/games/fortunes/work.dat
/usr/share/games/fortunes/work
/usr/share/games/fortunes/zippy.dat
/usr/share/games/fortunes/zippy
/usr/share/sol-games/fortunes.scm
/usr/games/fortune
[jdoe@frazz jdoe]$

To Locate a File:

  • locate fortune

    If you try to locate fortune, you’ll get a listing of all of the system files that contain “fortune” in them. This listing includes the fortune program, fortune data files for the fortune program to use, and related stuff. It’s a huge list in most cases (Code Listing 2.13).

✓ Tips

  • Use locate in combination with grep (see Using Regular Expressions with grep in Chapter 6) to narrow down your list, if possible.

  • Many people use locate to get a quick look at the directories that contain relevant files (/usr/share/games/fortunes contains a lot of files related to the fortune program), then other tools to take a closer look.

  • Not all systems include fortune—it’s certainly just a fun thing and not essential by any means. If you don’t “locate” it, try bash or csh to see how locate works. (See Chapter 8 for more information about different shells and their benefits and drawbacks.)


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.129.19