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

Commonly used Linux command sets refer to those

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

Share

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

The commonly used Linux command set refers to those. In view of this problem, this article introduces in detail the corresponding analysis and solutions, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

1 、 df

Df to check the usage of hard disk space

Check the usage of local hard disk space:

Du-s directory / file

Check the space occupied by all directories and files under the directory IDEA_workspace:

Last 5 orders were executed

7 、 source

Source makes the configuration file effective

After setting the alias mk in 5, it does not take effect in other shell dialogs, how to make it permanent.

In the ~ / .bashrc file, add alias mk= "mkdir-p" and it will not take effect at this time; source ~ / .bashrc will take effect.

Use wildcards to filter out a collection of files that meet the criteria

9. Special characters

# comment

\ escape characters, restore "special characters and wildcards" to normal characters

| | Pipeline |

Multiple commands execute delimiters successively

~ the user's home folder

The leader of the $variable

>, > > data stream redirection, > replace, > > append

'' contains single quotation marks of a string and does not have the function of variable replacement

"" contains double quotation marks of a string with variable replacement function

``contains commands, which represent commands that can be executed in advance, the same as $().

() is the beginning and end of the child shell

{} is a combination of command blocks

The use of the above special characters

10 、 grep

Grep filters the required row information through some filtering conditions in terms of behavior units.

Grep [- invc] 'find string' filename

-I is not case-sensitive

-n display line number

-v does not contain a lookup string

-c displays the total number of lines of strings that meet the requirements

Get the data you want from a data file:

Be familiar with the parameters of grep

16 、 sort

Sort sorts the contents of the data, by default by string type

Sort [- nrtku] filename

-n sort using "pure number"

-r reverse sort

-u uniq, when the same data appears, only one row is displayed as a representative

The-t delimiter (separated by default by Tab key)-k specifies which partition to sort by

Use sort to sort the data in the file:

Sort

17 、 uniq

Uniq retains only one row of adjacent rows with the same content in rows.

Uniq [- ic] filename

-I ignore case

-c count adjacent rows with the same content

Sort and count the data in the data:

Sort the data in data and count the number of entries.

18 、 wc

Wc counts how many words, characters, and lines are contained in a file.

Wc [- cl] filename

-c calculates the number of characters in file name

-l calculate the number of rows in file name

Count the number of lines of zhangguanghui 25 in data files

Count the number of rows in the data that contain zhangguanghui

19 、 awk

Awk 'condition type 1 {action 1} condition type 2 {action 2}.' Filename

Awk cuts each line of data according to a character (the default space character) and assigns it to $1, $2, and $3 in turn (n is the number of segments cut); then calculates condition type 1, and executes action 1 if the condition is met; then calculates condition type 2, and performs action 2 if the condition is met. Then follow the above steps to process each row of data in turn.

There are also some special characters: $0 represents the entire row of data; NF each row of data is cut into the total number of fields; NR indicates which row of data is currently processed by awk; FS specifies the delimiter, which is the space character by default.

BEGIN {Action 1; Action 2} indicates some preparatory work that is performed before the execution of the awk command. For example, if we want to specify a delimiter, we need to specify it in advance in BEGIN.

END {Action 1; Action 2} indicates some end of work performed after the awk has processed each row of data.

Calculate the age of all users in data2 and:

Calculate the age of all users in data2 and

20. |

| | indicates pipeline and data channel |

Cmd1 | cmd2 | the output of cmd3 cmd1 is the input of cmd2, and the output of cmd2 is the input of cmd3.

Take the line containing the "zhangguanghui" string from the data

Count the number of lines in the data that contain the string "zhangguanghui"

21 、 xargs

Xargs reads the data in stdin and segments it with spaces or line break characters, splits the data of stdin into arguments, and assigns arguments to the next command to execute.

Xargs [- pn0] command

-p ask the user when executing each command

-n is followed by a number indicating that several parameters are used each time the command command is executed.

-0 if the data entered into stdin contains special characters, such as `,\, etc., this parameter restores it to normal characters.

The grep, sort, uniq, awk and other commands described above all support pipe commands, but some commands do not support pipes, such as chmod. For example, we want to modify the files in a directory to be executable:

Modify some files in a directory to be executable

22 、 find

Find [PATH] [option] [command]

Option:

(1) related to time,-mtime,-atime,-ctime

(2) related to users,-uid,-gid,-user,-group,-nouser,-nogroup

(3) parameters related to file permissions and names,-name,-size,-type,-perm

Command

(1)-exec command, for example:-exec ls-l {}\

Where {} represents the content found by find, and\; represents the end of the command executed by-exec.

From the log file, delete the log from 2 days ago:

About the commonly used Linux command set refers to the answers to those questions are shared here, I hope the above content can be of some help to you, if you still have a lot of doubts to solve, you can follow the industry information channel to learn more related knowledge.

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