Linux 中which,find,locate,where,type命令



  1. Which命令:

$ man which
       which - shows the full path of (shell) commands.

       which [options] [--] programname [...]

       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.

       --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´.

           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

           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
           which() { declare -f | which --read-functions $@ }
           export -f which

           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 directories in PATH that start with a dot.

           Skip directories in PATH that start with a tilde and executables which reside in the HOME directory.

           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.

           Output a tilde when a directory matches the HOME directory. This option is ignored when which is invoked as root.

           Print version information on standard output then exit success-

           Print usage information on standard output then exit successfully.

       Which returns the number of failed arguments, or -1 when no `program-
       name´ was given.

       The recommended way to use this utility is by adding an alias (C
       shell) or shell function (Bourne shell) for which like the following:


            which ()
              (alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@
            export -f which


            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
            > echo `which q2`

       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.

       Carlo Wood <>







       find - search for files in a directory hierarchy

       find [path...] [expression]

       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.

       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.

       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.

              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.

              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.

              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命令



       whereis - locate the binary, source, and manual page files for a command

       whereis [ -bmsu ] [ -BMS directory...  -f ] filename ...

       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.

       -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.

       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 *






4 locate命令



       slocate - Security Enhanced version of the GNU Locate

       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]

          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.

       -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 cd


  $ type grep


  $ type -p grep





个人分类: Linux
上一篇ftp中遇到的Entering Extended Passive Mode问题
想对作者说点什么? 我来说一句