I/O重定向 Redirection
标准输入,标准输出,标准错误
stdin---->0(键盘只读) stdout------>1(终端只写) stderr-------->2(终端只写) 3,4,5,6...
file descriptors(FD 文件描述符)
进程使用文件描述符来管理打开文件
date 1>date.txt 输出重定向(覆盖)
date 1 >> date.txt 输出重定向(追加)
ls /home/xxxx >list.txt 2>error.txt (输出重定向list.txt 错误重定向error.txt)
ls /home/xxxx &>list.txt (输入错误都重定向list.txt)
ls /home/xxx >list.txt 2>/dev/null
ls /home/xxx &>dev/null
输入重定向
标准输入 < 等价于 0<
cat >file <<-EOF 直到eof就会结束
subshell (umask 777;touch file)
进程管道Piping
ll /dev |less 分页显示
ps aux |grep "http" 过滤http的进程
sort -t":" -k3 -n /etc/passwd -r(逆序) -t指定字段分隔符 -k指定列 -n按照数值排序
root@kali:~/Documents# ps aux --sort=-rss|head -7
统计当前/etc/passwd 中用户使用的shell类型
root@kali:~/Documents# ip addr |grep "inet"| awk '{print $2}'|awk -F"/" '{print $1}'
127.0.0.1
::1
192.168.3.129
fe80::20c:29ff:fe35:62eb
root@kali:~/Documents# ip addr |grep "inet"
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
inet 192.168.3.129/24 brd 192.168.3.255 scope global dynamic noprefixroute eth0
inet6 fe80::20c:29ff:fe35:62eb/64 scope link noprefixroute
root@kali:~/Documents# ip addr |grep "inet"| awk -F" " '{print $3}'
scope
scope
brd
scope
root@kali:~/Documents# ip addr |grep "inet"| awk -F" " '{print $2}'
127.0.0.1/8
::1/128
192.168.3.129/24
fe80::20c:29ff:fe35:62eb/64
root@kali:~/Documents#
tee管道
|tee 将输出重复输出到一个文件中
参数传递Xargs awk sed grep sort uniq