Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Search for Liunx files

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Find Which command for script files

The which command searches for the location of a system command in the path specified by the PATH variable and returns the first search result. That is, using the which command, you can see whether a system command exists and where the command is being executed.

Syntax: which [- a] command

-a: list all commands that can be found in the path directory

Example:

Which ifconfig

Which which # find the file name of which

File lookup whereis

The whereis command can only be used to search for program names, and if parameters are omitted, all information is returned.

Syntax: whereis [- bmsu] file or directory name

-l: you can list several main directories that whereis will query

-b: only look for files in binary format

-m: only look for files under the manual path of the description file

-s: only look for source source files

-u: find other special files that are not in the above three projects

Example:

Whereis ifconfig # find the ifconfig file name

Whereis-m passwd # is displayed only in files in man

Find command

Find, which is used to find files in the file tree and process them accordingly

-name: find files by file name

-perm: find files according to file permissions

-user: find the file according to the owner of the file

-size: find files according to the specified file size [+ n: greater than,-n: less than, n: equal to]

-group: find files according to the group to which they belong

-mtime: find the file according to the time when the file was changed.-n means within n days, + n means n days ago.

-newer file1 file2: find files whose change time is between file1 and file2

Example:

Find /-name xitai # finds a system-wide file named xitai

Find-mtime-2 # find files that have been modified in 48 hours

Find / usr/local-size + 100m # find files larger than 100m

Find-type d | sort # find all current target directories and sort them

Find / usr/local/apache-tomcat-admin/-perm 755 # find files with permissions of 755 in the specified directory

Find / etc/-newer / etc/passwd # find files that / etc/ are newer than / etc/passwd

Locate command

The locate command is actually another way to write "find-name", but much faster than the latter, because instead of searching for a specific directory, it searches for a database (/ var/lib/locatedb) that contains all the local file information. The Linux system automatically creates this database and automatically updates it once a day, so you can't find the most recently changed files using the locate command. To avoid this, you can manually update the database using the updatedb command before using locate.

Updatedb: create a locate database before the first run

Parameters:

-I: ignore case

-c: do not output file names, only count the number of files

-l: output only a few lines

-r: can be followed by regular expression

-S: output information about database files

Example:

Locate-l 5 passwd

If an error is reported:

Install first

Yum-y install mlocate

Another error was reported:

Initialization

Updatedb

Locate-l 5 passwd

Locate-S

Type

The type command is not really a lookup command, it is used to tell whether a command is native to shell or provided by a separate binary outside of shell. If a command is an external command, using the-p argument displays the path to the command, which is equivalent to the which command.

Example:

Type-p ifconfig

Grep

Used to filter / search the specified string. You can use regular expressions and can be used with a variety of commands.

Usage: grep [option] to find content source files

-A: displays the matching lines and the content after that

-B: display matching lines and previous content

-C: displays the matching lines and the contents before and after

-c: calculate the number of rows that match

-n: displays matching lines and line numbers

-I: ignore case

Regular expression

^:'^ grep' means to match all lines that begin with grep

'means to match all lines ending in grep

.: 'gr.p' means match' gr' followed by any character followed by'p'

: 'grep' indicates a line that matches one or more spaces followed by grep

[]: [Gg] rep means to match Grep and grep

[^]: [^ A-FH-Z] rep means to match lines that do not begin with AME F or H Mel Z and follow rep

Example:

Grep-n 'cc' aa.txt

Grep-in 'DD' aa.txt

Grep-vn 'cc' aa.txt

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report