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

Linux basic command

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Change the hostname

Hostnamectl set-hostname lan

Create directory command

Mkdir / xue

Recursively create a folder a/b/c

Mkdir-p a/b/c

Recursively create three directories of a _

Mkdir-p a / {brecrine cpene d}

View directory command

Ls / xue

Change the current directory / location

Cd / home

Cd ~

Cd-

Print the current working directory

Pwd

Create a file or modify a file timestamp

Modify the change time of the file

Ls-l

Touch-yearly 07101530' 1.txt

Stat command

Displays the status of the file or file system.

# usage stat [parameters] file

Parameter list:

-L,-- dereference follow the link

-f,-- file-system displays the file system status instead of the file status

-c-- the format= format uses the specified output format instead of the default value, replacing a new line each time with the specified format

-- printf= format is similar to-- format, but interprets backslash escape characters and does not use line breaks

The end of the output. If you still want to use line breaks, you can use them in the format

Add "\ n"

-t,-- terse outputs in a concise format

-- help displays this help and exits

-- version displays version information and exits

Format output parameters:

An Octal permissions

% An outputs permissions in a readable manner

# instance 1

[root@master tmp] # stat 1.txt

File: '1.txt'

Size: 0 Blocks: 0 IO Block: 4096 regular empty file

Device: fd00h/64768d Inode: 17348002 Links: 1

(permission) Access: (0644) Uid: (0 / root) Gid: (0 / root)

(recently visited) Access: 2018-07-10 1515 Suzhou 3015 00.000000000 + 0800

(recently changed) Modify: 2018-07-10 1515 Suzhou 3015 00.000000000 + 0800

(recently altered) Change: 2018-11-07 15 purl 38 purl 36.400989868 + 0800

Birth:-

# instance 2, display file permissions

[root@master tmp] # stat-c% a 1.txt

six hundred and forty four

[root@master tmp] # stat-c% A 1.txt

-rw-r--r--

First acquaintance of vim

Vi/vim operation flow:

Vi opens the file and enters the command mode. You can enter the I command and enter the edit mode. In edit mode, after you start typing the string, press esc to return to the command mode, press: enter the bottom line command mode: W write does not exit: wq! Write and force exit method, command vi

Vim

Using vi to open oldboy.py, the default is command mode, you need to enter a Life is short,i use python I to enter edit mode, and then enter the text "command"

Press the ESC key to return to command mode

Enter: wq! Force save exit

W write write

Q quit exit

! Compulsion

Or: X save exit

: Q do not save exit

: q! Do not save forced exit

View the contents of the file

View the file and display the line number

Cat-n xxx.py

Cat, view the file

Cat xxx.py

Put a $symbol at the end of each line

[root@master tmp] # cat-E 1.txt

Append text to a file

Cat > > / tmp/oldboy.txt > overweight orientation, appending text to the end of the file

2. > redirect the symbol, clear all the contents of the original file, and then overwrite the text to the end of the file

3.

< 输入重定向 4. /opt/ps.txt 找到/tmp目录下所有txt文件 ls /tmp|grep '.txt' 检查mariadb的端口是否存活 netstat -tunlp |grep mariadb grep命令 语法: grep [参数] [--color=auto] [字符串] filename 参数详解: -i : 忽略大小写 -n : 输出行号 -v : 反向选择 --color = auto : 给关键词部分添加颜色 grep "我要找什么" /tmp/a.txt 排除 -v,排除我要找的东西 grep -v "我要找什么 /tmp/a.txt head和tail命令 head显示文件前几行,默认前10行 tail显示文件后几行,默认后10行 #查看前五行 head -5 /tmp/a.txt #查看后五行 tail -5 /tmp/a.txt #持续刷新显示 tail -f a.log #显示文件10-30行 head -30 /tmp/a.txt |tail -21 sed命令 sed sed是一种流编辑器,它是文本处理中非常中的工具,能够完美的配合正则表达式使用,功能不同凡响。处理时,把当前处理的行存储在临时缓冲区中,称为"模式空间"(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有 改变,除非你使用重定向存储输出。Sed主要用来自动编辑一个或多个文件;简化对文件的反复操作;编写转换程序等。 命令格式 sed [options] 'command' file(s) sed [options] -f scriptfile file(s) 选项 -e或--expression=:以选项中的指定的script来处理输入的文本文件; -f或--file=:以选项中指定的script文件来处理输入的文本文件; -h或--help:显示帮助; -n或--quiet或--silent:仅显示script处理后的结果; -V或--version:显示版本信息。 -i ∶插入, i 的后面可以接字串 sed命令 a\ 在当前行下面插入文本。 i\ 在当前行上面插入文本。 c\ 把选定的行改为新的文本。 d 删除,删除选择的行。 D 删除模板块的第一行。 s 替换指定字符 h 拷贝模板块的内容到内存中的缓冲区。 H 追加模板块的内容到内存中的缓冲区。 g 获得内存缓冲区的内容,并替代当前模板块中的文本。 G 获得内存缓冲区的内容,并追加到当前模板块文本的后面。 l 列表不能打印字符的清单。 n 读取下一个输入行,用下一个命令处理新的行而不是用第一个命令。 N 追加下一个输入行到模板块后面并在二者间嵌入一个新行,改变当前行号码。 p 打印模板块的行。 P(大写) 打印模板块的第一行。 q 退出Sed。 b lable 分支到脚本中带有标记的地方,如果分支不存在则分支到脚本的末尾。 r file 从file中读行。 t label if分支,从最后一行开始,条件一旦满足或者T,t命令,将导致分支到带有标号的命令处,或者到脚本的末尾。 T label 错误分支,从最后一行开始,一旦发生错误或者T,t命令,将导致分支到带有标号的命令处,或者到脚本的末尾。 w file 写并追加模板块到file末尾。 W file 写并追加模板块的第一行到file末尾。 ! 表示后面的命令对所有没有被选定的行发生作用。 = 打印当前行号码。 把注释扩展到下一个换行符以前。 sed替换标记 g 表示行内全面替换。 p 表示打印行。 w 表示把行写入一个文件。 x 表示互换模板块中的文本和缓冲区中的文本。 y 表示把一个字符翻译为另外的字符(但是不用于正则表达式) \1 子串匹配标记 & 已匹配字符串标记 sed元字符集 ^ 匹配行开始,如:/^sed/匹配所有以sed开头的行。 $ 匹配行结束,如:/sed$/匹配所有以sed结尾的行。 . 匹配一个非换行符的任意字符,如:/s.d/匹配s后接一个任意字符,最后是d。 匹配0个或多个字符,如:/*sed/匹配所有模板是一个或多个空格后紧跟sed的行。 [] 匹配一个指定范围内的字符,如/[ss]ed/匹配sed和Sed。 [^] 匹配一个不在指定范围内的字符,如:/[^A-RT-Z]ed/匹配不包含A-R和T-Z的一个字母开头,紧跟ed的行。 (..) 匹配子串,保存匹配的字符,如s/(love)able/\1rs,loveable被替换成lovers。 & 保存搜索字符用来替换其他字符,如s/love/&/,love这成love。 \< 匹配单词的开始,如:/\ 匹配单词的结束,如/love\>

/ matches lines that contain words ending in love.

The x {m} repeats the character XMagol m times, for example: / 0 {5} / matches a line with 5 zeros.

X {m,} repeat the character x at least m times, such as: / 0 {5,} / matches lines with at least 5 zeros.

The character x is repeated at least m times and no more than n times, for example: / 0 {5 ~ 10} / matching lines of 5 ~ 10 zeros.

Sed actual use case

# replace all oldboy in oldboy.txt to oldboy_python

# the result is output to the screen and will not be written to the file

Sed's Universe OldBoyman / tmp/oldboy.txt

# use the option-I to match the first aaaa on each line and replace it with a_python, and write to the file

Sed-I's AAA _ AAA _ A _ AAA _ AAA _ python _ tmp/a.txt

# using the replacement tag g, you can also replace all matches

Sed-I's _

# delete the second line of the file

Sed-I '2d' / tmp/a.txt

# Delete blank lines

Sed-I'/ ^ $/ d' / tmop/a.txt

# Delete the second line of the file, and all lines at the end

Sed '2d` / tmp/a.txt

# display 10-30 lines

-p-- print

-n-- cancel the default output

Sed-n'10 30p' / tmp/a.txt

Which command

The which command is used to find and display the absolute path of a given command, and the environment variable PATH holds the directory that needs to be traversed to find the command.

The which command looks for files that match the criteria in the directory set by the environment variable $PATH.

That is, using the which command, you can see whether a system command exists and where the command is being executed.

Which pwd

Which python

Scp command

Grammar

Scp [optional parameter] Local source file remote file tag

Parameters.

-r: copy the entire directory recursively

-v: output in detail

-Q: no transmission progress bar is displayed

-C: allow compression

Transfer local files to a remote address

Scp local file remote user name @ remote ip: remote folder /

Scp local file remote user name @ remote ip: remote folder / remote file name

Enter the local folder to the remote address

Scp-r Local folder remote user name @ remote ip: remote folder /

Du command

Usage

Du [parameter] [file or directory]

-s display totals

-h is displayed in the unit of k _ ~ M ~ G, which is highly readable.

Show the space occupied by a directory or file

# follow nothing, which shows all file sizes in the current directory

Du

# display the total size of / home

Du-sh / home

Top command

The top command is used to dynamically monitor information such as process activity and system load.

First line (uptime)

System time host run time number of user connections (who) average load of system 1, 5, 5, 15 minutes

Line 2: process information

Total number of processes running number of processes sleeping number of processes stopped number of zombie processes

Line 3: cpu information

1.5 us: user space as a percentage of CPU

0.9 sy: percentage of CPU occupied by kernel space

0.0 ni: percentage of CPU occupied by processes that have changed priorities in the user's process space

97.5 id: percentage of idle CPU

0.2 wa: percentage of CPU time waiting for input and output

0.0 hi: percentage of hardware CPU interrupt occupancy

0.0 si: percentage of soft interrupt occupancy

0.0 st: percentage of virtual machine occupancy

Line 4: memory information (similar to the free command on line 5)

8053444 total: total physical memory

7779224 used: total amount of memory used

274220 free: total free memory (free+used=total)

359212 buffers: amount of memory used as kernel cache

Line 5: swap information

8265724 total: total swap partition

33840 used: total number of swap partitions used

8231884 free: total free swap area

4358088 cached Mem: the total amount of buffered swap area, the contents of the memory are swapped out to the swap area, and then swapped into memory, but the used swap area is not covered, these contents of the swap area already exist in the size of the swap area in memory, and the corresponding memory can be swapped out again without having to write to the swap area.

Chattr command

Lock the file, only write data, and cannot delete the file

Chattr + an a.txt

Chattr-an a.txt

Lsattr command

View file hidden properties

Lsattr a.txt

Linux time synchronization

The date command of linux can display the current time or set the system time

/ / modify the hardware time based on the system time

[root@lan ~ 10:29:07] # hwclock-w

/ / modify the system time based on the hardware time

[root@lan~ 10:29:21] # hwclock-s

Ntp time server

Client update time

Ntpdate-u ntp.aliyun.com

Wget command

Used to download files at the terminal

Wget-O / etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

Details page

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