linux xargs grep,linux tips : find grep xargs awk curl单行命令搞定备忘录 | 一半君的总结纸...

搜索所有子文件夹,找到包含 ilm_swapShapes 的所有*.mel 文件,不显示路径里有 versions的 ,结果显示成 @#$%.mel – Line number : XX grep的第一个match

find /searchPath -not -iwholename "*/versions/*" -name "*.mel" -exec grep -in -m 1 ilm_swapShapes {} /dev/null \; | awk -F: '{print ""$1 " - Line number : "$2" "$3}'

网上搜索以后 有人说不推荐用xargs,除非同时用-print0 不然万一路径里有空格或是特殊符号就会不对了

edit: xargs 后面加 -0 也许就可以了吧 但是依然

It is not possible for xargs to be used securely, since there will always be a time gap between the production of the list of input files and their use in the commands that xargs issues. If other users have access to the system, they can manipulate the filesystem during this time window to force the action of the commands xargs runs to apply to files that you didn’t intend.

如何删除其他文件,保留符合match的文件

如果是bash,extglob必须是on状态

shopt -s extglob

# *.lnx留下,其他的删了

$ rm !(*.lnx)

# 找到所有的结尾不是 _new.html 的 file

find . -maxdepth 1 -type f | grep -v '_new.html$'

# 另一种写法

find . -maxdepth 1 -type f -not -name '*_new.html'

关闭显示器,这个在用中古笔记本长时间运行某个任务时也许会需要

sleep 1;xset dpms force off

如何对多个文件逐个执行同一个命令

find /some/directory -maxdepth 1 -type f -exec cmd option {} \; > results.out

一行必杀奥义 Here is a quick solution using find and also sorting files by their modification date:

find directory/ -maxdepth 1 -type f -print0 | \

xargs -r0 stat -c "%y %n" | \

sort | cut -d' ' -f4- | \

xargs -d "\n" -I{} cmd -op1 {}

如何完全不显示output到console里,在你不想出来太多垃圾干扰视线的时候用

curl http://www.google.com > /dev/null 2>&1 &

此处的关键点是 2>&1 其含义是

The 1 denotes standard output (stdout). The 2 denotes standard error (stderr).

So 2>&1 says to send standard error to where ever standard output is being redirected as well. Which since it’s being sent to /dev/null is akin to ignoring any output at all.

查看当前shell

echo $0

改变当前shell prompt

# 临时改比如

PS1='\u:\W\$ '

实时查看log

tail -f /path/to/thefile.log

curl先下载再解压

curl /path/to/xxx.tar.gz | tar xz

curl /path/to/xxx.tar.bz2 | tar xj

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值