linux 文本操作

1.查看文件
cat somefile 一次性将文件内容全部输出(控制台)
more somefile 可以翻页查看, 下翻一页(空格) 上翻一页(b) 退出(q)
less somefile 可以翻页查看,下翻一页(空格) 上翻一页(b),上翻一行(↑) 下翻一行(↓)
head somefile 查看文件头部
tail somefile 查看文件尾部
tail -n 10 -f -s 1 ./log.log 没1秒展示log.log文件最后10行

3.grep pattern file
3.1 grep “被查找的字符串” 文件名
3.2 grep –e “正则表达式” 文件名
grep test test* #查找前缀有“test”的文件包含“test”字符串的文件
testfile1:This a Linux testfile! #列出testfile1 文件中包含test字符的行
testfile_2:This is a linux testfile! #列出testfile_2 文件中包含test字符的行
testfile_2:Linux test #列出testfile_2 文件中包含test字符的行

2.重定向
>覆盖
>>追加

sh test.sh 1>log 2>log # 标准输出和标准错误都会各自打开log
sh test.sh 1>log 2>&1 # 标准输出打开log,而标准错误,定向到标准输出.这样只打开了一次log
sh test.sh 1>/dev/null 2>&1

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值