Linux中which,find,locate,where,type命令使用总结:
- Which命令:
$ man which
NAME
which - shows the full path of (shell) commands.
SYNOPSIS
which [options] [--] programname [...]
DESCRIPTION
Which takes one or more arguments. For each of its arguments it prints to stdout the full path of the executables that would have been executed when this argument had
been entered at the shell prompt. It does this by searching for an executable or script in the directories listed in the environment variable PATH using the same algo-
rithm as bash(1).
This man page is generated from the file which.texinfo.
OPTIONS
--all, -a
Print all matching executables in PATH, not just the first.
--read-alias, -i
Read aliases from stdin, reporting matching ones on stdout. This is useful in combination with using an alias for which itself. For example
alias which=´alias | which -i´.
--skip-alias
Ignore option `--read-alias´, if any. This is useful to explicity search for normal binaries, while using the `--read-alias´ option in an alias or function for
which.
--read-functions
Read shell function definitions from stdin, reporting matching ones on stdout. This is useful in combination with using a shell function for which itself. For
example:
which() { declare -f | which --read-functions $@ }
export -f which
--skip-functions
Ignore option `--read-functions´, if any. This is useful to explicity search for normal binaries, while using the `--read-functions´ option in an alias or function
for which.
--skip-dot
Skip directories in PATH that start with a dot.
--skip-tilde
Skip directories in PATH that start with a tilde and executables which reside in the HOME directory.
--show-dot
If a directory in PATH starts with a dot and a matching executable was found for that path, then print "./programname" rather than the full path.
--show-tilde
Output a tilde when a directory matches the HOME directory. This option is ignored when which is invoked as root.
--version,-v,-V
Print version information on standard output then exit success-
fully.
--help
Print usage information on standard output then exit successfully.
RETURN VALUE
Which returns the number of failed arguments, or -1 when no `program-
name´ was given.
EXAMPLE
The recommended way to use this utility is by adding an alias (C
shell) or shell function (Bourne shell) for which like the following:
[ba]sh:
which ()
{
(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@
}
export -f which
[t]csh:
alias which ´alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde´
This will print the readable ~/ and ./ when starting which from your
prompt, while still printing the full path when used from a script:
> which q2
~/bin/q2
> echo `which q2`
/home/carlo/bin/q2
BUGS
The HOME directory is determined by looking for the HOME environment
variable, which aborts when this variable doesn´t exist. Which will
consider two equivalent directories to be different when one of them
contains a path with a symbolic link.
AUTHOR
Carlo Wood <carlo@gnu.org>
SEE ALSO
bash(1)
WHICH(1)
Find命令
NAME
find - search for files in a directory hierarchy
SYNOPSIS
find [path...] [expression]
DESCRIPTION
This manual page documents the GNU version of find. find searches the directory tree rooted at each given file name by evaluating the given expression from left to
right, according to the rules of precedence (see section OPERATORS), until the outcome is known (the left hand side is false for and operations, true for or), at which
point find moves on to the next file name.
The first argument that begins with â-â, â(â, â)â, â,â, or â!â is taken to be the beginning of the expression; any arguments before it are paths to search, and any
arguments after it are the rest of the expression. If no paths are given, the current directory is used. If no expression is given, the expression â-printâ is used.
find exits with status 0 if all files are processed successfully, greater than 0 if errors occur.
EXPRESSIONS
The expression is made up of options (which affect overall operation rather than the processing of a specific file, and always return true), tests (which return a true
or false value), and actions (which have side effects and return a true or false value), all separated by operators. -and is assumed where the operator is omitted.
If the expression contains no actions other than -prune, -print is performed on all files for which the expression is true.
OPTIONS
All options always return true. They always take effect, rather than being processed only when their place in the expression is reached. Therefore, for clarity, it
is best to place them at the beginning of the expression.
-daystart
Measure times (for -amin, -atime, -cmin, -ctime, -mmin, and -mtime) from the beginning of today rather than from 24 hours ago.
-depth Process each directoryâs contents before the directory itself.
-follow
Dereference symbolic links. Implies -noleaf.
-help, --help
Print a summary of the command-line usage of find and exit.
-maxdepth levels
Descend at most levels (a non-negative integer) levels of directories below the command line arguments. â-maxdepth 0â means only apply the tests and actions to
the command line arguments.
-mindepth levels
Do not apply any tests or actions at levels less than levels (a non-negative integer). â-mindepth 1â means process all files except the command line arguments.
-mount Donât descend directories on other filesystems. An alternate name for -xdev, for compatibility with some other versions of find.
-noleaf
Do not optimize by assuming that directories contain 2 fewer subdirectories than their hard link count. This option is needed when searching filesystems that
。。。。。。。太长了省略
3 whereis命令
NAME
whereis - locate the binary, source, and manual page files for a command
SYNOPSIS
whereis [ -bmsu ] [ -BMS directory... -f ] filename ...
DESCRIPTION
whereis locates source/binary and manuals sections for specified files. The supplied names are first stripped of leading pathname components and any (single) trailing
extension of the form .ext, for example, .c. Prefixes of s. resulting from use of source code control are also dealt with. whereis then attempts to locate the
desired program in a list of standard Linux places.
OPTIONS
-b Search only for binaries.
-m Search only for manual sections.
-s Search only for sources.
-u Search for unusual entries. A file is said to be unusual if it does not have one entry of each requested type. Thus âwhereis -m -u *â asks for those files
in the current directory which have no documentation.
-B Change or otherwise limit the places where whereis searches for binaries.
-M Change or otherwise limit the places where whereis searches for manual sections.
-S Change or otherwise limit the places where whereis searches for sources.
-f Terminate the last directory list and signals the start of file names, and must be used when any of the -B, -M, or -S options are used.
EXAMPLE
Find all files in /usr/bin which are not documented in /usr/man/man1 with source in /usr/src:
example% cd /usr/bin
example% whereis -u -M /usr/man/man1 -S /usr/src -f *
FILES
/{bin,sbin,etc}
/usr/{lib,bin,old,new,local,games,include,etc,src,man,sbin,
X386,TeX,g++-include}
/usr/local/{X386,TeX,X11,include,lib,man,etc,bin,games,emacs}
SEE ALSO
chdir(2V)
4 locate命令
NAME
slocate - Security Enhanced version of the GNU Locate
SYNOPSIS
slocate [-qi] [-d <path>] [--database=<path>] <search string>
slocate [-i] [-r <regexp>] [--regexp=<regexp>]
slocate [-qv] [-o <file>] [--output=<file>]
slocate [-e <dir1,dir2,...>] [-f <fstype1,...>] <[-l <level>] [-c] <[-U <path>] [-u]>
slocate [-Vh] [--version] [--help]
DESCRIPTION
Secure Locate provides a secure way to index and quickly search for files on your system. It uses incremental encoding just like GNU locate to compress its database
to make searching faster, but it will also store file permissions and ownership so that users will not see files they do not have access to.
This manual page documents the GNU version of slocate. slocate Enables system users to search entire filesystems without displaying unauthorized files.
OPTIONS
-u Create slocate database starting at path /.
-U <dir>
Create slocate database starting at path <dir>.
-e <dir1,dir2,...>
Exclude directories from the slocate database.
-f <fstype1,...>
Exclude files on specific file systems from the slocate database.
-c Parse â/etc/updatedb.confâ when updating the slocate database.
-l <level>
Security level. 0 turns security checks off. This will make searchs faster. 1 turns security checks on. This is the default.
-i Does a case insensitive search.
-q Quiet mode. Error messages are suppressed.
-n <num>
Limit the amount of results shown to <num>.
-r <regexp>
--regexp=<regexp> Search the database using a basic POSIX regular expression.
5 TYPE命令:
type命令其实不能算查找命令,它是用来区分某个命令到底是由shell自带的,还是由shell外部的独立二进制文件提供的。如果一个命令是外部命令,那么使用-p参数,会显示该命令的路径,相当于which命令。
type命令的使用实例:
$ type cd
系统会提示,cd是shell的自带命令(build-in)。
$ type grep
系统会提示,grep是一个外部命令,并显示该命令的路径。
$ type -p grep
加上-p参数后,就相当于which命令。
转一篇文章:http://www.linuxhaxor.net/?p=904