当前位置:网站首页>(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
边栏推荐
- Mujoco model learning record
- Pyqt5, draw a histogram on the control
- Basic usage of shell script
- . Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes
- Research Report on development monitoring and investment prospects of China's smart environmental protection industry (2022 Edition)
- Wechat applet blind box - docking wechat payment
- China acetonitrile market forecast and strategic consulting research report (2022 Edition)
- Redis master-slave realizes 10 second check and recovery
- The latest intelligent factory MES management system software solution
- 期货先锋这个软件正规吗安全吗?选择哪家期货公司更安全?
猜你喜欢

Thinkphp6 - CMS multi wechat management system source code

. Net cloud native architect training camp (permission system code implements actionaccess) -- learning notes

Mujoco model learning record

Intelligent operation and maintenance practice: banking business process and single transaction tracking

Happy new year | 202112 monthly summary

ACL 2022 | decomposed meta learning small sample named entity recognition

Heavy disclosure! Hundreds of important information systems have been invaded, and the host has become a key attack target

Explain in detail the process of realizing Chinese text classification by CNN

Record 3 - the state machine realizes key control and measures the number of external pulses

Leetcode 1380. Lucky numbers in the matrix (save the minimum number of each row and the maximum number of each column)
随机推荐
ISO 27001 Information Security Management System Certification
Detailed explanation of select in golang
Definition of rotation axis in mujoco
PHP implements sensitive word filtering system "suggestions collection"
Pyqt5, draw a histogram on the control
Development cost of smart factory management system software platform
From comedians to NBA Zhan Huang, check the encrypted advertisements during this super bowl
Glidefast consulting was selected as the elite partner of servicenow in 2022
網上股票開戶安全嗎?是否可靠?
Domestic spot silver should be understood
Intel's open source deep learning tool library openvino will increase cooperation with local software and hardware parties and continue to open
Is online stock account opening safe? Is it reliable?
Wechat applet blind box - docking wechat payment
ACM mm 2022 video understanding challenge video classification track champion autox team technology sharing
Can hero sports go public against the wind?
How to learn automated testing?
Samba basic usage
Small exercise -- subnet division and summary
目前炒期货在哪里开户最正规安全?怎么期货开户?
Unity3d extended toolbar