命令行的一些小技巧


Author: yifei / Created: Jan. 29, 2018, 3:51 a.m. / Modified: Jan. 29, 2018, 12:59 p.m. / Edit

最近工作中经常用到的一些组合命令,本来想提交到 commandlinefu.com 上,但是忘记了密码,怎么也登录不上去了,记到这里吧

dirname $0
du -sh `ls` | sort -rh
cd -
tail *
set -x # 显示每个执行的命令
set -e # 当有程序返回非0值时直接退出,相当于抛出异常
cat << EOF > /tmp/yourfilehere
These contents will be written to the file.
        This line is indented.
EOF
fd -t f -0 | xargs -0 sed -i /KeyWord/d

Always quote strings in bash. If you string is empty and you are testing it with == or !=, then there will be a "== is not uniary operator" error

find ./ -type f -exec sed -i -e 's/apple/orange/g' {} \;

from: https://stackoverflow.com/questions/6758963/find-and-replace-with-sed-in-directory-and-sub-directories


有任何问题可以发邮件到 kongyifei (at) gmail.com 讨论