管道与重定向

标准输入、标准正确输出、标准错误输出。

>        -------覆盖

>>        --------追加

正确输出:1> 1>>

[root@localhost ~]# date > 1.txt
[root@localhost ~]# cat 1.txt 
2023年 10月 21日 星期六 14:25:46 CST

错误输出:2> 2>>

[root@localhost ~]# cat /opt/uuuuu 2> 2.txt
[root@localhost ~]# cat 2.txt 
cat: /opt/uuuuu: 没有那个文件或目录

正确和错误输入到相同地方(&)

[root@localhost ~]# cat /etc/passwd &>3.txt
[root@localhost ~]# tail 3.txt 
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:999:998:User for polkitd:/:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
chrony:x:998:996::/var/lib/chrony:/sbin/nologin
nginx:x:997:995:nginx user:/var/cache/nginx:/sbin/nologin

输入重定向

标准输入:        <

[root@localhost ~]# cat > 1.txt<<EOF 
> 
> 
> 
> hello world
> EOF
[root@localhost ~]# cat 1.txt 



hello world

管道(|)

将前一条命令的输出结果交给管道后

查看/etc/passwd 交给管道过滤包含root的行

[root@localhost ~]# cat /etc/passwd |grep root
root:x:0:0:root:/root:/bin/bash
operator:x:11:0:operator:/root:/sbin/nologin

排序(sort)

参数:

        -t 指定分隔符

        -k 指定列

        -n 按数值

        -r 降序

以:为分隔符第二列按数值排序:

[root@localhost ~]# cat > 1.txt <<EOF
> 1:22
> 2:33
> 3:44
> 4:55
> 5:11
> EOF
[root@localhost ~]# cat 1.txt 
1:22
2:33
3:44
4:55
5:11
[root@localhost ~]# sort -t":" -n -k2 1.txt 
5:11
1:22
2:33
3:44
4:55

参数传递(xargs)

对:ls cp rm  管道不能执行。所以通过xargs。

[root@localhost ~]# cat 1.txt | xargs -i cp {} /opt/(目录)

{} :前面传过来的内容

-i:为了让大括号生效

目录时        -r

解释:前面传过来的东西交给大括号

常用小命令

查看目录及目录中的文件大小

[root@localhost ~]# du -h

[root@localhost ~]# du -h
4.0K	./2023-10-19-16:31:37
0	./.pki/nssdb
0	./.pki
8.0K	./aaa/static/css
196K	./aaa/static/font
204K	./aaa/static
1.6M	./aaa
4.0K	./.ssh
6.8M	.
查看目录的总大小

[root@localhost ~]# du -sh /etc/

[root@localhost ~]# du -sh /etc/
32M	/etc/
查看目录中有多少个文件

[root@localhost ~]# ls /etc/ | wc -l

[root@localhost ~]# ls /etc/ | wc -l
176

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值