Find, Whereis, locate, which search File command summary in Linux __linux

Source: Internet
Author: User
Tags file permissions
It programmer development must-all kinds of resources download list, the most complete IT resources in history, personal collection summary.


Find
Find is a very effective tool that traverses the current directory and even the entire file system to locate certain files or directories.
Primary options:-name find files by file name-perm file permissions to find a file-prune does not find a file in the currently specified directory-user find files by file owner-group locate files by the group to which they belong-mtime-n +n follow the file  The change time to find the file,-n indicates that the file change time is now n days, +n indicates that the file change time is now N days ago. -nogroup finds a file that does not have a valid owning group, that is, the group that the file belongs to does not exist-nouser find a file that has no valid owner-newer File1! File2 find change time than file File1 new but older file File2 file-type find a type of file
[File type: B Block device file d directory C character device file P pipe file L Symbolic link file f normal file]
-size N[c] Find files with a file length of n blocks, with C indicating the length of the file in bytes-depth when looking for a file, first look for the file in the current directory, and then look in its subdirectory-mount does not cross the file system mount point when locating files-follow if fin The D command encounters a symbolic link file,-cpio it to the file that the link points to, and uses the Cpio command on the matching file to back up the files to the disk device
(The rest of the options, please find the man, see further) some examples of finding command options: $ find/etc-type D # Search all directories under/etc directory $ find/etc-user Yaoyuan # Find text in/etc directory A document belonging to the main Yaoyuan $ find. -size +1000000c # Find files with a file length greater than 1 m bytes in the current directory


WhereisThe Whereis command looks for eligible files in the specified directory, and the file should be in the original code, binary, or help file.
Options:-B Find binaries only--find binaries only in set directory-F do not display the path name before the filename-M only find description file-M finds the description file only in the set directory----only finds the original code file------only finds the original code file in the set directory- u find files that do not contain the specified type
Whereis example $ whereis mysql MySQL:/usr/bin/mysql/etc/mysql/usr/share/mysql/usr/share/man/man1/mysql.1.gz
LocateThe locate command is used to find eligible files, and it will go to the database where the file and directory names are saved, and find the files or directories that match the criteria.
Option:-U establishes the database, starts with the root directory----establishes the database, can specify the start position-e will be excluded from the search scope-F to exclude specific file systems in the outside-Q Quiet mode, no error message-N at most n output-r to find with normal expressions The condition-o Specifies the name of the database-D specify the path to the database-H display auxiliary message-V show more messages----Display the version message of the program
(The Locate command can quickly find files in the search database, the database is updated by the UpdateDB program, updatedb by the cron daemon periodically, locate command in the search for the database than by the entire hard disk data to search for information faster, But the worse is locate found the file if only recently established or renamed, may not be found, in the default value, UpdateDB will run once a day, can be modified crontab to update the set value. (etc/crontab) Locate specifies to search for eligible files, which will store files and directory names in a database, find files or catalogs that conform to the template style criteria, and use special characters such as "*" or "?" , and so on) to specify the template style, such as the specified template is Kcpa*ner, locate will find all the start string is KCPA and the end of the NER file or directory, such as the name Kcpartner if the catalog name is Kcpa_ner, it lists all files that are included in the directory, including subdirectories. )
Locate Example:
$ locate Inittab/usr/lib/upstart/migrate-inittab.pl/usr/share/terminfo/a/ansi+inittabs
whichWhich is similar to where it is, only the set of the environment variables we set in the path of the search;
[Root@localhost ~]# which fdisk/sbin/fdisk

=============================================================================================================

1. Find

Find is the most common and powerful search command you can use to find any file you're looking for.

Find uses the following format:

  $ find < Specify directory > < specify conditions > < specify action >

-< Specify directory: the directory to search for and all of its subdirectories. The current directory is assumed by default.

-< Specify conditions: The characteristics of the file to search for.

-< Specify action: Perform specific processing of search results.

If nothing is added, find defaults to search the current directory and its subdirectories, and does not filter any results (that is, all files are returned) and displays them all on the screen.

Use example of Find:

  $ find.-name "my*"

Searches the current directory (with subdirectories, below) for all file names starting with my.

  $ find.-name "my*"-ls

Searches the current directory for all files whose filenames start with my, and displays their details.

  $ find.-type f-mmin-10

Searches the current directory for all normal files that have been updated in the last 10 minutes. If you do not add the-type f parameter, search for normal files + special files + directories.

2. Locate

The locate command is another way of writing "Find-name", but it is much faster than the latter because it does not search for a specific directory, but rather searches a database (/var/lib/locatedb), which contains all of the local file information. The Linux system automatically creates this database and updates it automatically every day, so you won't be using the locate command to find the most recently changed files. To avoid this, you can use the updatedb command to manually update the database before using locate.

Usages of the Locate command:

  $ locate/etc/sh

Search all files in the ETC directory that start with SH.

  $ locate ~/m

Searches the user's home directory for all files beginning with M.

  $ locate-i ~/m

Searches the user's home directory for all files that start with M and ignores case.

3. Whereis

The Whereis command can only be used for the search of program names, and only binary files (parameter-B), man description file (parameter-m), and source code files (parameter-s) are searched. If the argument is omitted, all information is returned.

Usages of the Whereis command:

  $ whereis grep

4. Which

The which command works by searching for the location of a system command in the path specified by the path variable and returning the first search result. That is, by using the which command, you can see whether a system command exists, and which location is executing the command.

Usages of the which command:

  $ which grep

5. Type

The type command is not really a lookup command, which is used to distinguish whether a command is brought by a shell or provided by a separate binary file outside the shell. If a command is an external command, then the-P argument displays the path to the command, equivalent to the which command.

Use instance of type command:

  $ type cd

The system prompts that the CD is the Shell's own command (build-in).

  $ type grep

The system prompts that grep is an external command and displays the path to the command.

  $ type-p grep

With the-p argument, it is equivalent to the which command.

Finish

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.