几个shell小技巧
1,sudo !!
以root权限执行上一条命令。
2,cd -
回到上一次的目录。
3,^old^new
替换前一条命令里的部分字符串
4,man ascii
显示ascii码表
5,tail -f /path/to/file.log | sed ‘/^Finished: SUCCESS$/ q’
当file.log中出现Finished: SUCCESS时就退出tail
6,ssh root@4.6.140.237 bash < /path/to/local/script.sh
远程运行一段脚本
7,curl ifconfig.me
当本机在内网的时候,可以通过此命令查看外网ip
8,lsof -i
实时查看本机网络服务的活动状态
9,python -m SimpleHTTPServer
在当前目录启动HTTP服务,可以通过http://localhost:8000访问
10,history | awk ‘{CMD[$ 2]++; count++;} END { for (a in CMD )print CMD[ a] “ “ CMD[ a]/ count* 100 “% “ a }’ | grep -v “./” | column -c3 -s “ “ -t | sort -nr | nl | head -n10
很有意思的一条命令,列出你最常用的10条命令。
这十个命令是最近在《码农》杂志偶然看到的,觉得很有趣,总结在此。将来在工作中遇到一些很麻烦的操作,也应该自己想想是不是可以编写一些简单的shell脚本简单地处理。
Written on October 11, 2015