Linux Command - Four swordsman
A: Linux command of AWK
Symbol: beginning ^
$ End
awk is a language text processing, a powerful text analysis command!
1: The second extract files in each row
Before extracting the text content
Command: CAT 1.txt | awk '{Print ($ 2)}'
In AWK command, it will be part of the text of each column as a part of!
Or we can specify the delimiter, specifying the extraction of a part of!
We have 2 Separated Values
命令:cat 1.txt | awk -F "2" '{print($2)}'
The output of the first three lines
Print each line of the file last field
命令:cat 1.txt|awk "2" '{print($NF)}'
Two: Linux command of sed
sed is a stream of the encoders, which is in very text processing tool
Perfectly fit regular expressions they use, can function were extraordinary.
Extract the contents of the text before
1: Remove the blank content within the text!
Command: CAT 1.txt | sed '/ ^ \ S * $ / d'
Remove the comment line
Command: CAT 1.txt | sed '/^#.*/d'
Here is not the practical operation!
2: Replace the text of the things
命令:cat 1.txt | sed 's#^192#ym#g'
The 192 replaced ym
3: add things at the beginning or end of the text
命令:cat 1.txt | sed 's#^#https://#g'
4:在文本后面添加东西
命令:cat 1.txt | sed 's#$#/login.php#g'
三:Linux命令 之 grep
grep 指令用于查找内容包含指定的范本样式的文件,如果发现某文件的内容符合所指定的范本样式
预设 grep 指令会把含有范本样式的那一列显示出来。
若不指定任何文件名称,或是所给予的文件名为 -,则 grep 指令会从标准输入设备读取数据。
示范前的文本内容:
1:查看含有12的行
命令:cat 1 | grep 12
2:匹配含有 12 的行
3:查找以 192 开头的行
命令:cat 1 | grep -E '^192'
4:查找以 php 结尾的行
命令:cat 1 | grep -E 'php$'
5:在多级目录中对文本进行递归查找。
grep “passwd” /etc -rn
-r 为递归 -n 显示关键字出现在第几行
四:Linux命令 之 find
find 命令:用来在指定目录下查找文件。
任何位于参数之前的字符串都将被视为欲查找的目录名。
如果使用该命令时,不设置任何参数,则find命令将在当前目录下查找子目录与文件。
并且将查找到的子目录和文件全部进行显示。
1:在 / 目录下,按照大小查找,并只输出前5行
命令:find / size 1000k | head -n 5
2:在当前目录下查找以1开头的文件
命令:find -name 1*
3:按照属主查找
命令:find / -user root | head -n 5
4:搜索7天内当前目录下修改过的文件
命令:find . -type f -mtime -7 |head -n 10
-7 代表7天内 7 代表前7天那一天 +7 代表7天前
5:搜索10分钟内当前目录下修改过的文件
find . -type f -mmin -10
find . -atime -1 -type f
搜索当前目录下一天内被访问的文件
(-1 代表1天内 1代表前1天那一天 +1 代表1天前)
find . -atime -10 -type f
搜索当前目录下10分钟内被访问的文件
find . -ctime -1 -type f
搜索当前目录下一天内状态被改变(列如权限)的文件
针对Web 服务器日志进行分析
统计IP地址的访问数量并按照数量进行排序
cat access_log |awk ‘{print($1)}’|sort |uniq -c | sort -nr |more