Linux related Find File command (find locate which whereis type)

Source: Internet
Author: User
Tags system log

The following is excerpted from: http://blog.csdn.net/jessica1201/article/details/8139249

The contents of the label are their own additions:

We often need to find a file in the system, so how do we accurately and efficiently determine the exact location of a file in the system on a Linux system? I summed up several commands for locating files in a Linux system.

1. Find command

Find is the most common and powerful lookup command that can find any type of file.

The general format of the Find command is: Find < Specify directory >< specify criteria >< specify action, that is, find Pathname-options [-print-exec-ok]

Parameter explanation:

Pathname:pathname is the search directory and its subdirectories, which are the current directory by default

Commonly-used option options:

-name: Find files by file name

-user: Find files According to the owner of the file

-group: Find files according to the group to which the files belong

-perm: Find files according to file permissions

-prune: Not found in the currently specified directory

For example, a file named 1111 is known to be in the/directory,/etc,/user, and/user/bin directories, so let's take a look at the role of-prune.

Find-name 1111-print looks for a file named 1111 under the current directory and its subdirectories.

Find. -path./etc-prune-o-name 1111-print looks for a file named 1111 in the current directory and its subdirectories (in addition to the/etc directory and its subdirectories).

Find. -path./usr-prune-o-name 1111-print looks for a file named 1111 in the current directory and its subdirectories (except for the/USR directory and its subdirectories).

Find.−PATH./USr/bin−< Span id= "mathjax-span-22" class= "Mi" >o− pa th / et c -prune-o-name 1111-print looks for a file named 1111 in the current directory and its subdirectories (except for the/usr/bin directory and its subdirectories; etc directory and its subdirectories). Because the command line does not recognize parentheses directly, use the escape character \, and a space before and after.

Note: When the Find command does not add any parameters, it indicates that the search path is the current directory and its subdirectories, the default action is-print, which means that no results are filtered, that is, all the files are output.

-mtime-n +n: According to the file modification time to find the file,-n means that the file modification time is now less than n days, +n means that the file modification time is now N days ago

-type: Find a type of file (b: block device file; d: directory file; c: Character device file; p: Pipeline file; l: Link file; F: normal file)

-nogroup: Find files that do not have a valid owning group, that is, the group to which the file belongs does not exist in/etc/group

-nouser. Find a file with no valid owning master, that is, the owner of the file does not exist in/etc/passwd

This command is commonly used as a lookup system error log, and to clear the system log

Find/var/log-type F|xargs grep "failed"//Find failed characters inside the log file

Find/var/log-type f-exec rm-v {} \; Clearing the System log

2. Locate command

The locate command is actually another way of writing "Find-name", but it is much faster than find, unlike finding. Because it does not search for a specific directory, it searches for the specified file in a database (/var/lib/locatedb). The secondary database contains all the information of the local file, the database is created automatically by the Linux system, the database is updated by the UpdateDB program, UpdateDB is created periodically by cron Daemon, and is updated daily by default. So use locate to command you to search for files that are not up to date, unless you manually update the database with the UpdateDB command before you use the Locate command to locate the file.

Note : Each time a new file is updated and deleted, the file information that is saved in the database before UpdateDB is not changed, that is, after a new file is added, UpdateDB does not search for the specified file with locate. Also delete a file information is already in the database file, updatedb before using locate can still search the file information, although at this time the file does not exist.

This command may have systems that are not installed by default: package default name Mlocate

Mlocate.x86_64:An utility for finding files by name

3. Whereis command

The Whereis command can only be used to search for binaries (-B), source code files (-s), and description files (-m). If the argument is omitted, all information is returned.

4. Which command

The which command searches the path specified by the path variable for the location of the specified system command. Use the Echo $PATH to display the value of the current path variable.

This command may have systems that are not installed by default: package default name

[Email protected] toor]# Rpm-qa|grep which
Nodejs-which-1.0.5-10.fc21.noarch
Which-2.20-8.fc21.x86_64

5. Type command

The type command is primarily used to differentiate whether a command is provided by a shell or an externally independent binary file. If the shell comes with it, the command will be prompted for the Shell Buildin, otherwise the location of the command will be listed. For example: The CD is a shell-brought command, when found with which, which will follow the path variable set to search, the results show no CD in ... ; Use the type CD to display the CD as the Shell Buildin command. SSH is not a shell-brought command, and the path to SSH is displayed when you use type.

    • Previous CSDN scoring rules small loophole
    • The next Linux user information, group information and password management
Top
0

Linux related Find File command (find locate which whereis type)

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.