Search for Linux commands and files

Source: Internet
Author: User

Occasionally forget some of the commands or files, the following commands can help us quickly find the command or file

1. Search for commands

Command:which

Function: Search for commands in the directory under Path configuration

Usage: which [-a] [command]

Parameters:

-A: Lists all the commands found from the directory configured in path, instead of displaying only the first found command

Example 1: Find the man command, with only one query result displayed

    

Example 2: Find the man command and display all the query results

    

From the above two can be seen there is no parameter-a difference

Note the point:

This command is based on the directory configured by path to search for the Unknown Origin command, and which the full command name appended to it. There are commands that are built in bash and cannot be detected by which.

2. Search for files or directory names

Command:whereis

Function: Search for a file or directory name in the specified special directory

Usage: whereis [-BLMSU] [file or directory name]

Parameters:

-B: Only binary files are queried

-L: Lists all directories for Whereis queries

-M: Find only below the description file manual

-S: Only source files are found

-U: Search for other special files not in the-[bms] project

Example 1: Find related files for the cat command

    

Example 2: Look for cat-related files below the description file manual

    

Note the point:

Whereis is followed by a complete file or directory name

Command:Locate

Function: In the established database, find files or directories

Usage: Locate-[ICLSR] Partial file name

Parameters:

-I: Ignore case

-C: Do not output file name, only calculate the number of files found

-L: The number of rows to output after, for example, output 3 lines plus parameter-L 3

-S: Details of the repositories used by the output locate

-R: The display method of the normal expression can be followed

Example 1:

Find files and directories containing history in the file name or directory containing history, and display only 6 rows

    

Example 2: Displaying information about the database used by locate

    

Here you can see the directory and file name of the database inside the system.

Attention:

There is a limit to using the locate query, because the command will be queried in the specified repository, but the database will usually be updated automatically one day (each Linux distribution will be different) so that new files or directories will not be found. We can use the command updatedb to manually update the database, updatedb instructions will read the/etc/updatedb.conf file inside the settings, and then go to the hard drive to search for files or directories, and then update the database, so that the new file or directory can be queried.

Command:Find

Function: Search for files or directories

Usage: Find [path] [option] [action]

Parameters:

1. Time-related parameters: Total-atime,-ctime and-mtime

-mtime N: N is a number, which represents a file that has been modified within one day of the nth Day

-mtime +n: A file that shows the content modified before n days (excluding n days itself)

-mtime-n: Displays files that have been modified within n days (including the N-day itself)

-newer File:file for an existing file that shows new files than file

List the files or directories in which the system has modified the contents for the last 24 hours

    

Lists files and directories below the root home directory that are newer than the Anaconda-ks.cfg file

    

2. Parameters related to user or group

-uid N # is a number, n is the user ID of the user and is recorded in the file/etc/passwd

-gid N, N is a number, the group ID of group is recorded in file/etc/shadow

-user Name:name is the user's account name, such as root

-group Name:name is a group name, such as the users

-nouser: Finding files that the owner of the file does not have in/etc/passwd

-nogroup: Finding files that are not in the/etc/group file group

Query all files and directories belonging to Kelvin under the home directory

    

Find files that are not owned by anyone under the root directory

    

3. Parameters related to file permissions and names

-name filename: Search for files with file name filename

-size [+-]size: Search for files larger than size (+) or small (-), size in units of: C: Representative of Byte,k: representative of KByte

-type type: Types of search files, types are mainly: general normal file (f), device file (b,c), directory (d), Nexus (L), socket (s) and FIFO (p)

-perm mode: Search for file permissions equal to mode

-perm-mode: Search file permissions must include all files in the mode permission

-perm/mode: Search file permissions include any one mode permission file

Locate the passwd file under the root directory

    

Find files containing passwd in the root directory

    

Find the socket type file in the Run directory

Querying the root directory for files with s or T permissions

    

Querying the root directory for files with s or T permissions and displaying the results in a ls-al manner

    

Show files larger than 1M below the root directory

Search for Linux commands and files

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.