0x01 cut命令
Linux cut命令用于显示每行从开头算起 num1 到 num2 的文字。
参数
-b :以字节为单位进行分割。这些字节位置将忽略多字节字符边界,除非也指定了 -n 标志。
-c :以字符为单位进行分割。
-d :自定义分隔符,默认为制表符。
-f :与-d一起使用,指定显示哪个区域。
-n :取消分割多字节字符。仅和 -b 标志一起使用。如果字符的最后一个字节落在由 -b 标志的 List 参数指示的
范围之内,该字符将被写出;否则,该字符将被排除
示例
一,选取每行以空格分隔的第二部分字符
cat flag | cut -d ' ' -f 2
-d 指定分隔符为空格
-f 选择第二部分
二、提取每一行的第1个字符,就这样:
cat flag | cut -c 1
0x02 tr命令
Linux tr 命令用于转换或删除文件中的字符。
参数说明:
-c, --complement:反选设定字符。也就是符合 SET1 的部份不做处理,不符合的剩余部份才进行转换
-d, --delete:删除指令字符
-s, --squeeze-repeats:缩减连续重复的字符成指定的单个字符
-t, --truncate-set1:削减 SET1 指定范围,使之与 SET2 设定长度相等
--help:显示程序用法信息
--version:显示程序本身的版本信息
示例
将a替换为b
echo "aaaaaaaa" | tr a b
删除a
echo "aaaabbbb" | tr -d a
0x03 命令行中使用代理(http_proxy)
http_proxy=127.0.0.1:9999 wget http://www.laruence.com/
0x04 AWK命令
很详细的文章:Linux三剑客之awk命令
awk使用
awk '{pattern + action}' {filenames}
常用 awk 内置变量
awk中的print作用就是输出,举几个例子来学习
test.txt
使用
$0
输出一整行
[root@root]# awk '{print $0}' test.txt
You may notice this week's edition of Royal News is a little late.
We'll be honest -- we had an entirely different version of the newsletter ready for you.
...............................................
使用$0
$1
会输出第一第二个单词,$3 $4以此类推
[root@root]# awk '{print $1}' test.txt
You
We'll
But
The
Despite
He
# 输出 第一个单词+空格+第二个单词
[root@root]# awk '{print $1 " " $2}' test.txt
You may
We'll be
But minutes
The Queen's
Despite all
He was
可以使用-F
指定分隔符,不指定默认为空格
# 输出一整行
[root@root]# awk -F ":" '{print $0}' /etc/passwd
root:x:0:0:root:/root:/usr/bin/zsh
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
...............................................
# 输出第一个单词
[root@root]# awk -F ":" '{print $1}' /etc/passwd
root
daemon
...............................................
只查看文件内第20到第30行的内容(企业面试)
awk '{if(NR>=20 && NR<=30) print $1}' /etc/passwd
0x05 xargs 命令
xargs(英文全拼: eXtended ARGuments)是给命令传递参数的一个过滤器,也是组合多个命令的一个工具
find /sbin -perm +700 |ls -l #这个命令是错误的
find /sbin -perm +700 |xargs ls -l #这样才是正确的