linux的常见目录

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
一,指令

  1. more指令 —— 分页显示文件内容

  2. less指令 —— 可以向前或向后查看文件内容

  3. head指令 —— 查看文件开头的内容

  4. tail指令 —— 显示文件尾部的内容

  5. cat指令 —— 显示文件内容

练习

1、查看test文件的前5行内容(3种方式)
head -5 test
head -n5 test
cat -n test | head -n5
more

2、查看test文件的第9行和第10行内容(文件一共10行,有几种方式?)
tail -n2 test
cat test | head | tail -n2
head test | tail -n -2
head

3、查看test文件的前5行内容并输出到文件test1
head -n5 test >>test1
cat test | head -5 >>test1
cat test;head -5 test >>test1

4、统计出/etc/passwd文件中以login结尾的有多少行
grep “login " / e t c / p a s s w d ∣ w c − l g r e p − c " l o g i n " /etc/passwd | wc -l grep -c "login "/etc/passwdwclgrepc"login” /etc/passwd

5、查找出test文件中包含linux的行并显示行号(2种方式)
cat -n test | grep “linux”
grep -n “linux” test
tail -n +1 test | cat -n | grep “linux”

6、过滤出以#开头和空行的行
grep -vE “#|$” test

7、统计文件test中linux出现的次数
grep -o “linux” test|wc -l
grep -o “linux” test|wc -w
grep -o “linux” test | grep -c “linux”

8、查找出/etc/passwd文件中包含user或者used的行
grep -E “user|used” /etc/passwd
grep “user|used” /etc/passwd
grep “use[rd]” /etc/passwd

9、统计root或者Root在test文件中共匹配到多少行
grep -i “root” test | wc -l
grep -ic “root” test

grep -E “root|Root” test
grep “[rR]oot” test

10、查看/dev目录下以sd开头和中间包含a字母的文件个数
ls /dev | grep “^sd” | grep “a” | wc -l

思考题:统计/opt目录下的文件大小并升序/降序排列
du -a /opt | sort -nr

如何用grep匹配有 的 行 / 以 的行/以 /结尾的行
匹配有 的 行 : g r e p " [ 的行: grep "[ :grep"[]" test
grep “\$” test

结 尾 的 行 g r e p " [ 结尾的行 grep "[ grep"[]$" test
grep “$$” test

\:转义字符

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值