5.3. Using Find

You can find everything on your system that might be run as a command by:

# find -H  / -type f -perm +0111 -print

But you'll have to go through that list carefully and eliminate various shared-objects and shared libraries which aren't actually possible to run stand-alone.

If you mean just what is part of the base system, then:

# find -H /bin /sbin /boot /usr/bin /usr/sbin /usr/libexec \
        -type f -perm +0111 -print

You'll probably need to add a few more directories to that list to get everything.

count the number of files that begin with 'db' in the name, under the '/path/to/dir' directory. man find and man wc for more action:

find /path/to/dir -type f -name db\* -print | wc -l

You can use find with the -mtime switch to locate old files that are candidates for removal.

How do I count the number of certain files in a directory? I want to count how many files begin with db.

The key command is wc. It is a nice, simple little command that does one thing and one thing well - it counts "words". If you don't give it any flags, it tells you the number of lines, words, and bytes. Using wc -l will count the number of lines. So you pipe the output of a command to it and it will count stuff for you. Thus:

% ls db* |wc -l

will give you a single number telling you the number of lines in its input; in this case, the input is the output of ls db*, which is a simple listing of all the files in the current directory beginning with 'db'. Thus, you get a count of the number of files in the directory that begin with db. A very typical Un*x way of doing things - string together building block commands to get your output.

To see the 10 largest files on a directory or partition, use:

%: du /partition_or_directory_name | sort -rn | head

In Unix, to locate commands by keyword lookup, you can use apropos followed by appropriate keywords. This command will then show the sections from the manual pages that contain any of the keywords in the section title. The command considers each word separately, and ignores the case of letters. Words that are part of other words are listed. Thus, looking for the word compile will find all instances of compiler also.

For example, to find the word firewall in the manual pages, enter:

% apropos firewall
firewall(7)              - simple firewalls under FreeBSD
ip6fw(8)                 - controlling utility for IPv6 firewall
ipfw(8)                  - IP firewall and traffic shaper control program
xfwp(1)                  - X firewall proxy

This can also be accomplished using man -k firewall which will yield the same results.

The whereis can be useful:

% whereis vi
vi: /usr/bin/vi /usr/share/man/man1/vi.1.gz /usr/src/usr.bin/vi

To search for files that match a particular name, use find(1); for example:

% find / -name "*GENERIC*" -ls

will search '/', and all subdirectories, for files with 'GENERIC' in the name.