linux命令总结

linux命令总结

文本提取

awk -F ‘,’ ‘{print $(NF-2)}’ logs.txt
awk begin{RS=EOF}’{gsub(/\n/," ");print}’ uid.txt
以冒号分割,取第二个字段
awk -F ‘:’ ‘{print $2}’ sd.txt

统计文本的行数

文件test1.txt有17行
方法一:
awk ‘{print NR}’ test1.txt | tail -n1
管道前所有行号,管道后则打印最后一行
或者:
awk ‘END{print NR}’ test1.txt
方法二:
grep -n ‘’ test1.txt | awk -F : ‘{print $1}’ | tail -n1
或者:
grep -n ‘’ test1.txt | awk -F : ‘END{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 1}̲' 方法三: sed -n '=’ test1.txt
备注:统计文件的行数,等同于cat test1.txt | wc -l 命令(下面方法中所述),具体点就是-n抑制输出, $到最后一行,=打印行号。
方法四:
wc -l test1.txt
或者:wc -l test1.txt | awk ‘{print $1}’
又或者:cat test1.txt | wc -l

文本处理时,经常要删除重复行,下面是三种方法

第一,用sort+uniq,注意,单纯uniq是不行的。
sort -n test.txt | uniq
第二,用sort+awk命令,注意,单纯awk同样不行,原因同上。
sort -n $file | awk ‘{if($0!=line)print; line=$0}’
第三,用sort+sed命令,同样需要sort命令先排序。
sort -n f i l e ∣ s e d ′ file | sed ' filesed!N; /^(.*)\n\1$/!P; D’

查看cpu核数

cpu个数

cat /proc/cpuinfo| grep “physical id”| sort| uniq| wc -l

cpu核数

cat /proc/cpuinfo| grep “cpu cores”| uniq

内存

free -m

ps -ef|grep test|grep -v grep |awk ‘{print $2}’
ps -ef|grep test|grep -v grep |awk ‘{print $2}’|xargs kill -9

nohup指定输出的目录文件

原命令:
nohup /home/work/… Push.php &
重定向:
nohup /home/work/… Push.php >> pushDout0207.out 2>&1 &

0 – stdin (standard input),1 – stdout (standard output),2 – stderr (standard error) ;
2>&1是将标准错误(2)重定向到标准输出(&1),标准输出(&1)再被重定向输入到output文件中。

批量杀死进程

ps -ef|grep ftp://ftprmb:Z5YqkGebhfaR9k7r@yq01 | awk ‘{print $2}’|xargs kill -9

批量删除git 分支

git branch | grep ‘test’ |xargs git branch -D

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值