Linux file search command usage details, linux Command Usage Details

Source: Internet
Author: User

Linux file search command usage details, linux Command Usage Details
Find command

Linux find commandUsed to find files in a specified directory. Any string located before the parameter will be considered as the directory name to be searched. If you do not set any parameters when using this command, the find command searches for subdirectories and files in the current directory. In addition, all the subdirectories and files found are displayed.

Syntax

# find . -name "*.c"

List all common files in the subdirectories of the current directory

locate passwd

Additional instructions

Locate is different from find: find is to find the hard disk, locate is only found in the/var/lib/slocate database.

The locate speed is faster than the find speed. It is not a real search, but a database. Generally, the file database is in/var/lib/slocate. db, so the locate search is not real-time, but is based on database updates. Generally, the system maintains the database by itself, or you can manually upgrade the database. The command is:

locate -u 
Slocate command

Linux slocate command to find files or directories.

Slocate itself has a database that stores information about files and directories in the system.

Syntax

Slocate [-u] [-- help] [-- version] [-d <directory>] [searched file]

Parameters:

Option Description
-D <directory> or-database = <directory> Specifies the directory where the database is located;
-U Update the slocate database;
-Help Show help;
-Version Displays version information.

Instance

Run the "slocate" command to display the file path information with the keyword "fdisk" in the file name. Enter the following command:

$ Slocate fdisk # display the path information of the file with the fdisk keyword in the file name

After the preceding command is executed, the command output is as follows:

$ Slocate fdisk # display the path information of the file containing the fdisk keyword in the file name/root/cfdisk # list of searched file paths/root/fdisk/usr/include/grub/ieee1275/ofdisk. h/usr/share/doc/util-Linux/README. cfdisk/usr/share/doc/util-Linux/README.fdisk.gz
Which command

The Linux which command is used to find files.

The which command searches for qualified files in the directory set by the environment variable $ PATH.

Syntax

Which [file...]

Parameters:

Option Description
-N <file name length> Specify the file name length. The specified length must be greater than or equal to the longest file name in all files.
-P <file name length> The parameter is the same as the-n parameter, but the <file name length> here includes the file path.
-W Specify the width of the field in the output time.
-V Displays version information.

Instance

Run the command "which" to view the absolute path of the command "bash" and enter the following command:

$ which bash

After the preceding command is executed, the output information is as follows:

/Bin/bash # absolute path of the bash executable program
Whereis command

The Linux whereis command is used to find files.

This command searches for files that meet the conditions in a specific directory. These files should belong to the original code, binary files, or help files.

This command can only be used to find binary files, source code files, and man manual pages. Generally, the locate command is used to locate files.

Syntax

Whereis [-bfmsu] [-B <directory>...] [-M <directory>...] [-S <directory>...] [file...]

Parameters:

Option Description
-B: searches for binary files only;  
-B <directory> Searches for binary files only in the specified directory;
-F The path name before the file name is not displayed;
-M Only search for instruction files;
-M <directory> Find the description file only in the specified directory;
-S Only search for original code files;
-S <directory> Search for the original code file only in the specified directory;
-U Search for files that do not contain the specified type.

Instance

Run the command "whereis" to view the location of the command "bash" and enter the following command:

$ whereis bash 

After the preceding command is executed, the output information is as follows:

bash:/bin/bash/etc/bash.bashrc/usr/share/man/man1/bash.1.gz 

Note: The above output information is the queried program name, bash path, and bash man manual page path from left to right.

To query binary or help files separately, run the following command:

$ whereis -b bash $ whereis -m bash 

The output information is as follows:

$ Whereis-B bash # display the bash command binary program bash:/bin/bash/etc/bash. bashrc/usr/share/bash # address of the bash command binary program $ whereis-m bash # display the bash Command help file bash: /usr/share/man/man1/bash.1.gz # bash Command help file address

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.