当前位置:网站首页>(6) VIM editor MV cat redirection standard input and output more pipe symbols head tail
(6) VIM editor MV cat redirection standard input and output more pipe symbols head tail
2022-07-01 18:12:00 【Nan Yunxi】
One 、 Knowledge supplement
1.1 env
Check the current terminal shell Of environment variable ( Global variables )
Among the contents found HISTSIZT=1000, That is, the number of historical orders is 1000
1.2 vim Use of editor
Linux Text editor under ,vi Updated version of
【 install vim Editor 】yum install vim -y( The virtual machine must be able to access the Internet )
1.2.1 touch and vim The difference between creating files
touch a.txt Just create an empty file , Don't write content into the file
vim a.txt Not only create files , At the same time, you can write content into it . If a.txt The file already exists , Is the use of vim Open this file , If it does not exist, it is new
1.2.2 Operation steps
- Press i Enter input ( Insert ) Pattern
- Press Esc Key to return to command mode
- Input :wq( Must be in English input mode , A lowercase letter )==> Exit and save
- It can be done by cat Connect the file name to check the file content
[[email protected] lianxi]# vim lihua.txt
[[email protected] lianxi]# cat lihua.txt
lihua
Chian
hunan
Li Hua
China
Two 、 Command to explain
2.1 mv
1. Move (Move) File or directory ==> shear
[[email protected] lianxi]# ls
hua.txt hunan lihua
[[email protected] lianxi]# mv lihua hunan
[[email protected] lianxi]# ls
hua.txt hunan
[[email protected] lianxi]# ls hunan
lihua
You can move multiple folders at the same time , You can also move files and folders at the same time . here , The destination must be a folder , Otherwise, it cannot accommodate multiple contents
[[email protected] lianxi]# mkdir liming
[[email protected] lianxi]# touch lihua.txt
[[email protected] lianxi]# ls
hua.txt hunan lihua.txt liming
[[email protected] lianxi]# mv lihua.txt liming/ hunan
[[email protected] lianxi]# ls
hua.txt hunan
[[email protected] lianxi]# ls hunan
lihua lihua.txt liming
2. If the target location is the same as the original location or the target folder does not exist , Is quite renamed ==> rename
[[email protected] lianxi]# ls
hua.txt hunan
[[email protected] lianxi]# mv hunan xiang
[[email protected] lianxi]# ls
hua.txt xiang
2.2 cat
Show the full contents of the file
【 Options 】-n Number each line of output
[[email protected] lianxi]# file lihua.txt
lihua.txt: UTF-8 Unicode text
[[email protected] lianxi]# cat -n lihua.txt
1 lihua
2 Chian
3 hunan
4 Li Hua
5 China
2.2.1 cat Detailed functions
cat - concatenate files and print on the standard output
Connect files and output content to the screen
Connection file : At the same time, the contents of multiple files can be output at the same time , And connect them
[[email protected] lianxi]# cat lihua.txt
lihua
Chian
hunan
Li Hua
China
[[email protected] lianxi]# cat xiaoming.txt
Hello
xiaoming
[[email protected] lianxi]# cat lihua.txt xiaoming.txt
lihua
Chian
hunan
Li Hua
China
Hello
xiaoming
2.2.2 Redirect
Put the content that should be output on the screen , Redirect to a file , Changed his output direction
standard input Standard input ==》 keyboard
standard output Standard output ==》 The screen
Redirection actually changes the direction of output , The standard output is to output to the screen , Redirection can be output to a file
[[email protected] lianxi]# cat lihua.txt xiaoming.txt >lihua_xiaoming.txt
[[email protected] lianxi]# ls
hua.txt lihua.txt lihua_xiaoming.txt passwd xiang xiaoming.txt
[[email protected] lianxi]# cat lihua_xiaoming.txt
lihua
Chian
hunan
Li Hua
China
Hello
xiaoming
> Output redirection : If the following file does not exist, create , If it exists, the original content will be overwritten
[[email protected] lianxi]# echo hello,world >hello.txt
[[email protected] lianxi]# ls
hello.txt hua.txt lihua.txt lihua_xiaoming.txt passwd xiang xiaoming.txt
[[email protected] lianxi]# cat hello.txt
hello,world
[[email protected] lianxi]# echo HELLO,WORLD >hello.txt
[[email protected] lianxi]# cat hello.txt
HELLO,WORLD
>> Append output redirection : If the following file does not exist, create a new , If it exists, the original content will not be overwritten , Just append at the end
[[email protected] lianxi]# echo 123 >test.txt
[[email protected] lianxi]# cat test.txt
123
[[email protected] lianxi]# echo 456 >>test.txt
[[email protected] lianxi]# cat test.txt
123
456
2.2.3 tac
Read the contents of the file upside down
[[email protected] lianxi]# cat test.txt
123
456
[[email protected] lianxi]# tac test.txt
456
123
2.3 more
Full screen display of file content
Pagination display : Page by page display
2.3.1 Interactive operation method
- Press Enter Key down line by line
- Press the space bar to scroll down one screen , Press b Key up one screen
- Press q Key to exit
[[email protected] lianxi]# cp /var/log/messages .
[[email protected] lianxi]# more messages
2.3.2 | Pipe symbol
The function is to send the output of the previous command to the following command as input
Pipeline essentially realizes the communication between processes , It is a way of communication between processes
[[email protected] lianxi]# cat -n messages |more The line number is displayed , There is paging display
2.3.3 ps aux
see Linux Information about the current instantaneous process in the system
- USER Refers to which user started the process
- PID Is the number of the process process id
- %CPU Consumed by the process cpu Usage rate
- %MEM Memory consumed by the process memory
- COMMAND Is the name of the running process
[[email protected] lianxi]# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.6 128148 6756 ? Ss 2 month 14 0:05 /usr/lib/syst
root 2 0.0 0.0 0 0 ? S 2 month 14 0:00 [kthreadd]
root 4 0.0 0.0 0 0 ? S< 2 month 14 0:00 [kworker/0:0H
2.3.4 wc
Count the number of lines in a file 、 word 、 byte
- first 2 Express 2 That's ok
- the second 2 Express 2 Word
- 8 Represents eight bytes
A Chinese character occupies 3 Bytes , An English letter accounts for 1 Bytes , A space 、 A enter key takes up one byte
[[email protected] lianxi]# cat test.txt
123
456
[[email protected] lianxi]# wc test.txt
2 2 8 test.txt
[[email protected] lianxi]# cat test.txt |wc -l Statistics test.txt How many lines are there in the document
2
ps aux|wc -l Statistics ps aux How many lines of command output
ps aux|more Display process information in pages
【 Options 】
-l The statistical number of rows
-w Count the number of words
-c Count bytes
2.3.5 $()
effect : Give priority to the commands inside , Then return the execution result of the command
user_num=$(cat /etc/passwd |wc -l) Execute first cat /etc/passwd |wc -l Get the results , And then assign it to user_num This variable
[[email protected] lianxi]# cat /etc/passwd |wc -l
30
[[email protected] lianxi]# user_num=$(cat /etc/passwd |wc -l)
[[email protected] lianxi]# echo $user_num
30
2.3.6 less
And more The same command , But there are more extensions , The operation method is basically similar , There are some differences
【page down】 Page up 【page up】 Page down
【 differences 】more and less
- After the content is displayed ,less Do not exit ,more Will automatically exit
- less Can press 【page down】【page up】, and more no way
2.4 head
purpose : Look at the beginning of the file ( Default is header 10 That's ok )
Format :head -n numbuer file name
Format :head - Numbers file name
[[email protected] lianxi]# head -3 messages be equal to [[email protected] lianxi]# head -n 3 messages
[[email protected] lianxi]# cat -n messages |head -3
1 Feb 13 17:27:01 192 rsyslogd: [origin software="rsyslogd" swVersion="8.24.0-55.el7" x-pid="1069" x-info="http://www.rsyslog.com"] rsyslogd was HUPed
2 Feb 13 17:37:33 192 dhclient[864]: DHCPREQUEST on ens33 to 192.168.255.254 port 67 (xid=0x7c8e74b0)
3 Feb 13 17:37:33 192 dhclient[864]: DHCPACK from 192.168.255.254 (xid=0x7c8e74b0)
2.5 tail
purpose : Look at the end of the file ( The default is after 10 That's ok )
Format :tail -n numbuer file name
Format :tail - Numbers file name
2.5.1 tail Advanced usage of
tail -n +number Used before you don't want to display number The content of the line , Show from page number From the beginning to the end of the line
[[email protected] lianxi]# df -Th
file system type Capacity Already used You can use Already used % Mount point
devtmpfs devtmpfs 475M 0 475M 0% /dev
tmpfs tmpfs 487M 0 487M 0% /dev/shm
tmpfs tmpfs 487M 7.7M 479M 2% /run
tmpfs tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 17G 1.6G 16G 10% /
/dev/sda1 xfs 1014M 138M 877M 14% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
[[email protected] lianxi]# df -Th|tail -n +2 From the second line to the end
devtmpfs devtmpfs 475M 0 475M 0% /dev
tmpfs tmpfs 487M 0 487M 0% /dev/shm
tmpfs tmpfs 487M 7.7M 479M 2% /run
tmpfs tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root xfs 17G 1.6G 16G 10% /
/dev/sda1 xfs 1014M 138M 877M 14% /boot
tmpfs tmpfs 98M 0 98M 0% /run/user/0
tail -f test.txt Dynamic monitoring test.txt Changes in the contents of the document : Stare at the end of the file , Once there is input , Output to the user immediately
It is generally used when we look at the change of a log file
Press Ctrl + C force finish
[[email protected] lianxi]# tail -f test.txt
123
456
HELLO
TEST
( Copy label ) Use the redirection function in another terminal to add
[[email protected] ~]# cd lianxi
[[email protected] lianxi]# echo HELLO >>test.txt
[[email protected] lianxi]# echo TEST >>test.txt
边栏推荐
- MES production equipment manufacturing execution system software
- Is it safe to open a stock account by mobile phone? What do you need to bring with you to open an account?
- Software construction scheme of smart factory collaborative management and control application system
- Apk signature process introduction [easy to understand]
- ZABBIX alarm execute remote command
- 开发那些事儿:EasyCVR平台添加播放地址鉴权
- ISO 27001 Information Security Management System Certification
- Zabbix报警执行远程命令
- Cassette helicopter and alternating electric field magnetic manometer DPC
- Samba basic usage
猜你喜欢
Extract the compressed package file and retrieve the password
DNS
Set the style of QT property sheet control
How to retrieve the password for opening Excel files
2022 Heilongjiang latest fire protection facility operator simulation test question bank and answers
Nearly 60% of the employees strongly support Ctrip's "3+2" working mode, and work at home for two days a week
The method of real-time tracking the current price of London Silver
Samba basic usage
Penetration practice vulnhub range Tornado
Heavy disclosure! Hundreds of important information systems have been invaded, and the host has become a key attack target
随机推荐
June issue | antdb database participated in the preparation of the "Database Development Research Report" and appeared on the list of information technology and entrepreneurship industries
Review Net 20th anniversary development and 51aspx growth
Function, condition, regular expression
Apk signature process introduction [easy to understand]
Win10+vs2019 Community Edition compiling OpenSSL
Data warehouse (3) star model and dimension modeling of data warehouse modeling
. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
Zabbix报警执行远程命令
JS how to convert a string with a delimiter into an n-dimensional array
Fresh, 2022 advanced Android interview must know 100 questions (interview questions + answer analysis)
Gameframework eating guide
开发那些事儿:EasyCVR平台添加播放地址鉴权
D @ safety and dip1000
The new server is packaged with the source code of H5 mall with an operation level value of several thousand
Can hero sports go public against the wind?
Is it safe to open an ETF account online? What are the steps?
Good looking UI mall source code has been scanned, no back door, no encryption
Check log4j problems using stain analysis
Enter wechat applet
MES production equipment manufacturing execution system software