Linux-命令-文件查看和处理-小记

cat file1查看⽂件内容
cat -n file1查看内容并标示⾏数
cat xxx.txt查看xxx.txt文件内容
tac file1从最后⼀⾏开始反看⽂件内容
more file1查看⼀个⻓⽂件的内容
less file1类似more命令,但允许反向操作
head -2 file1查看⽂件前两⾏
tail -2 file1查看⽂件后两⾏
tail -f /log/msg实时查看添加到⽂件中的内容
grep codesheep hello.txt在⽂件hello.txt中查找关键词codesheep
grep ^sheep hello.txt在⽂件hello.txt中查找以sheep开头的内容
grep [0-9] hello.txt选择hello.txt⽂件中所有包含数字的⾏
sed 's/s1/s2/g' hello.txt将hello.txt⽂件中的s1替换成s2
sed '/^$/d' hello.txt从hello.txt⽂件中删除所有空⽩⾏
sed '/ *#/d; /^$/d' hello.txt从hello.txt⽂件中删除所有注释和空⽩⾏
sed -e '1d' hello.txt从⽂件hello.txt 中排除第⼀⾏
sed -n '/s1/p' hello.txt查看只包含关键词"s1"的⾏
sed -e 's/ *$//' hello.txt删除每⼀⾏最后的空⽩字符
sed -e 's/s1//g' hello.txt从⽂档中只删除词汇s1并保留剩余全部
sed -n '1,5p;5q' hello.txt查看从第⼀⾏到第5⾏内容
sed -n '5p;5q' hello.txt查看第5⾏
paste file1 file2合并两个⽂件或两栏的内容
paste -d '+' file1 file2合并两个⽂件或两栏的内容,中间⽤"+"区分
sort file1 file2排序两个⽂件的内容
comm -1 file1 file2⽐较两个⽂件的内容(去除'file1'所含内容)
comm -2 file1 file2⽐较两个⽂件的内容(去除'file2'所含内容)
comm -3 file1 file2⽐较两个⽂件的内容(去除两⽂件共有部分)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值