Home > Enterprise Linux Tips > Administrator > Finding stuff on Linux
Enterprise Linux Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ADMINISTRATOR

Finding stuff on Linux


Nigel McFarlane
12.15.2004
Rating: -4.40- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


It takes time to become an operating system virtuoso. Understanding the ins and outs of Windows takes a lot of time. UNIX and Linux are no different. If you're not that familiar with Linux, how can you find what you need amongst all the stuff that's there? Cryptically abbreviated filenames with historic baggage don't help, and the UNIX file system is typically much larger than most Windows installs. Here we look at some command line tactics for finding stuff.

Getting help

First of all, there's help. UNIX supplies four main flavors of help:

  1. command line help
  2. man(1) pages
  3. info(1) pages
  4. how-tos

Linux command line options use the short-and-long syntax started by the GNU project. Short options use a single minus sign and a letter or digit, long options use two minus signs and a whole word. For most tools, ls --help | less reports some useful help information, and passes it to the less(1) viewer so that you can scroll up and down. If --help won't work for a given tool, try -h, or just type the command without any arguments. If nothing happens in the last case, press Control-C to get the prompt back.

The man(1) command is short for "manual". It provides very terse, but mostly complete descriptions of most aspects of UNIX/Linux. The manual is divided into sections, with section 1 being commands, 2: kernal interfaces, 3: regular programming interfaces, 4: devices, 5: system files, 6: games, 7: standards and 8: networking. Others are also possible. Each section is divided into pages, one per command -- hence "manpages."

The notation "man(1)" means "entry for the 'man' command in section 1" Ensure the MANPAGER and PAGER environment variables aren't set, and that the MANPATH variable is set as follows:

export MANPATH=:/usr/share/man:/usr/X11R6/man:/usr/local/share/man

Then type this to read about the manual system:

man man

Type man ls to read about the "ls" command. The manual page for the shell, usually found with "man bash" or "man sh," is particularly information-dense. If you want to learn the shell, read that entry dozens of times, a small piece at a time, or grab a proper tutorial from elsewhere. To find a command, try man -k keyword (where "keyword" is some word related to the thing you're trying to find).

The info (and pinfo) tools hold manual information in a different format. They present hypertext help that you can navigate around with the arrow keys and the Enter key. Although the manpages often say that the info pages are more up to date, the info pages don't always contain more information. The info pages do cluster commands together into logical groups, which can help with discovery.

The final form of help comes in the form of how-tos. These are sets of reader-friendly tutorials that describe how to perform common system administration and configuration tasks. For most Linux distributions, they should appear in the directory /usr/share/doc. Read them with a plain editor, like vi.

Command versions

You might be more interested in versions than in help. Command versions can usually be had with one of these variants:

ls –version
ls –v
ls –V

Beware that "v" sometimes also stands for "verbose." If your Linux was installed with RPM, then the command rpm -q keyword will report the version of any package with 'keyword' in its description.

As a last resort, for binaries and library files, you can try strings filename which might dump out something that gives a version hint. For Linux itself, the command dmesg repeats all the information sent to the console when the machine was last booted.

Brute-force searching and the "find(1)" command

If help and versions aren't enough, then you may be reduced to brute-force searching of the disk. For a simple set of files, such as those reported by "ls," grep(1) is the most useful tool, with its simple or complex syntax options:

ls /etc | grep passwd
ls /etc | grep '[rR][cC]$'

Beyond that, Linux supports the find(1) command. It is similar to the Windows/DOS equivalent but far more powerful. It has tricky syntax: if you want to search for part of a filename, then remember to single-quote the regular expression that makes up the search term:

find /tmp -name '*foo*'

The find(1) command doesn't search file contents. For that you need to couple it with another command. The usual technique is to use xargs(1), which takes as input a set of strings and another command name, and pumps those strings into the other command as arguments. A very common use is:

find / -follow | xargs grep -l 'keyword'

This command searches the whole of the computer (quite slowly the first time) for any file containing the keyword 'keyword'. It reports the found filenames only. Be patient with this command; the second time it runs it will be far faster.

Finally, if you find yourself searching file content a lot, you might consider the glimpse system. The command glimpseindex(1) builds a massive but static index into the content of whatever files you specify. The glimpse(1) command is used to perform quick searches using that index. Rebuild the index regularly if you find that files are changing a lot.

Like all of UNIX, the story of finding stuff is a story about using the right tools. The technical information automatically available in a Linux computer is quite accurate and precise. That's not obvious immediately, but it is something greatly appreciated once you get going.


Rate this Tip
To rate tips, you must be a member of SearchEnterpriseLinux.com.
Register now to start rating these tips. Log in if you are already a member.


Submit a Tip




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Enterprise Linux Web Server & Application Server
HomeNewsTopicsITKnowledge ExchangeTipsBlogsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts