Linux就该这么学(课程笔记)4-?

这篇笔记详细介绍了Linux中的重定向、管道符、通配符和变量转义符的使用,包括如何进行输入输出重定向、使用管道符进行命令连接以及通配符在文件匹配中的应用。同时,讲解了常用的转义字符,如反斜杠、单引号、双引号和反引号的作用,并探讨了环境变量的重要性,特别是PATH变量在命令查找中的关键角色。此外,还提到了VIM编辑器的三种模式:命令模式、输入模式和末行模式。
摘要由CSDN通过智能技术生成

第四课

重定向

笔记: ll = ls -l

[root@linuxprobe ~]# ll
total 44
-rw-r--r--. 1 root root 1534 Mar 17 08:27 anaconda-ks.cfg
-rw-r--r--. 1 root root   99 Mar 16 17:44 a.txt
-rw-r--r--. 1 root root  123 Mar 16 17:45 b.txt
-rw-r--r--. 1 root root  123 Mar 16 17:45 c.txt
drwxr-xr-x. 3 root root   38 Mar 17 09:05 Desktop
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Documents
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Downloads
-rw-r--r--. 1 root root  126 Mar 17 16:39 haha
-rw-r--r--. 1 root root 1534 Mar 15 19:12 haha.cfg
-rw-r--r--. 1 root root   55 Mar 17 16:51 hoho
-rw-r--r--. 1 root root 1534 Mar 16 20:02 hoho.cfg
-rw-r--r--. 1 root root 1534 Mar 17 15:48 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Music
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Pictures
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Public
-rw-r--r--. 1 root root   85 Mar 16 18:24 sam
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Templates
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Videos
-rw-r--r--. 1 root root  200 Mar 17 08:29 xingxing
[root@linuxprobe ~]# ls -l
total 44
-rw-r--r--. 1 root root 1534 Mar 17 08:27 anaconda-ks.cfg
-rw-r--r--. 1 root root   99 Mar 16 17:44 a.txt
-rw-r--r--. 1 root root  123 Mar 16 17:45 b.txt
-rw-r--r--. 1 root root  123 Mar 16 17:45 c.txt
drwxr-xr-x. 3 root root   38 Mar 17 09:05 Desktop
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Documents
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Downloads
-rw-r--r--. 1 root root  126 Mar 17 16:39 haha
-rw-r--r--. 1 root root 1534 Mar 15 19:12 haha.cfg
-rw-r--r--. 1 root root   55 Mar 17 16:51 hoho
-rw-r--r--. 1 root root 1534 Mar 16 20:02 hoho.cfg
-rw-r--r--. 1 root root 1534 Mar 17 15:48 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Music
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Pictures
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Public
-rw-r--r--. 1 root root   85 Mar 16 18:24 sam
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Templates
drwxr-xr-x. 2 root root    6 Mar 15 19:14 Videos
-rw-r--r--. 1 root root  200 Mar 17 08:29 xingxing
[root@linuxprobe ~]# 

定向作为是为了写脚本做铺垫

输入重定向 < (命令<文件)

                        标准 > 覆盖 > 追加 >>

输出重定向(命令>文件)

                        错误 2>覆盖2> 追加>>

                        不论正确/错误全部输出到文件里面 &>

标准输出:正常的输出信息

比如:

[root@linuxprobe ~]# touch linuxprobe
[root@linuxprobe ~]# ls -l initial-setup-ks.cfg 
-rw-r--r--. 1 root root 1534 Mar 17 15:48 initial-setup-ks.cfg






错误/报错信息:

[root@linuxprobe ~]# ls -l hahahahha
ls: cannot access 'hahahahha': No such file or directory
[root@linuxprobe ~]# 

输出重定向

将命令原本要输出屏幕的内容输出到文件里面叫做输出重定向符
[root@linuxprobe ~]# ls -l initial-setup-ks.cfg 
-rw-r--r--. 1 root root 1534 Mar 17 15:48 initial-setup-ks.cfg
[root@linuxprobe ~]# ls -l initial-setup-ks.cfg > haha
[root@linuxprobe ~]# cat haha
-rw-r--r--. 1 root root 1534 Mar 17 15:48 initial-setup-ks.cfg
[root@linuxprobe ~]# 
[root@linuxprobe ~]# ls -l initial-setup-ks.cfg > haha
[root@linuxprobe ~]# ls -l initial-setup-ks.cfg > haha
[root@linuxprobe ~]# ls -l initial-setup-ks.cfg > haha
[root@linuxprobe ~]# ls -l initial-setup-ks.cfg > haha
[root@linuxprobe ~]# cat haha
-rw-r--r--. 1 root root 1534 Mar 17 15:48 initial-setup-ks.cfg
[root@linuxprobe ~]# ls -l initial-setup-ks.cfg >> haha
[root@linuxprobe ~]# cat haha
-rw-r--r--. 1 root root 1534 Mar 17 15:48 initial-setup-ks.cfg
-rw-r--r--. 1 root root 1534 Mar 17 15:48 initial-setup-ks.cfg
[root@linuxprobe ~]# 

[root@linuxprobe ~]# ls -l hahahah
ls: cannot access 'hahahah': No such file or directory
[root@linuxprobe ~]# ls -l hahahah &> hoho
[root@linuxprobe ~]# cat hoho
ls: cannot access 'hahahah': No such file or directory
[root@linuxprobe ~]# 

输入重定向

[root@linuxprobe ~]# wc -l /etc/passwd
45 /etc/passwd
[root@linuxprobe ~]# wc -l < /etc/passwd
45
[root@linuxprobe ~]# 

管道符 |

命令A | 命令B

命令A -> 命令B

管道符会将命令输出的结果传给命令B

可以想象成流水线作业,A把肉结块交给B把肉串在一起再交给C烤(烤串)

统计一下有多少个用户能够登录我的服务器:

然后将我们原先要输出到屏幕的信息通过管道符交给命令wc -l:

[root@linuxprobe ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值