整理一下自己平时用的比较多的一些工具和命令,便于后期查阅。

Linux 系统

强烈推荐一个网站:http://cheat.sh/,能够查询所有 linux 系统相关的命令。

磁盘类

1
2
3
4
5
# 查询系统磁盘剩余空间
df -h

# 查看当前空间文件的大小
du -h

文件操作类

本地操作

  1. 查询 path1 目录中的 java 文件:

    1
    $ find path1 -type f -name "*.java"
  2. path1 目录同步 java 文件到 path2 中,并且: 1) 同步目录结构;2) 删除源文件;3) 删除 path2 中的空文件夹

    1
    $ rsync -arv --prune-empty-dirs --remove-source-files --include='*/' --include='*.java' --exclude='*' path1 path2
  3. 删除 path1 目录中所有的空文件夹:

    1
    $ find path1 -type d -depth -empty -exec rmdir "{}" \;

远程操作

  1. 同步远程服务器上的文件到本地

    1
    $ rsync -avz --progress -e "ssh -p $portNumber" user@remoteip:/path/to/files/ /local/path/

进程 & 端口

  1. 检查端口运行

    1
    $ netstat -vanp tcp | grep $port

    1
    $ sudo lsof -i tcp:$port 

统计分析

统计日志中的平均响应时间:

1
$ cat witness.log | grep latency | \awk '{sum+=$14} END {print "Count: ",NR;print "Avg :",sum/NR}'

Mac 系统

brew

官网:https://brew.sh/

安装
1
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
常用命令
1
2
3
4
5
$ brew update #更新brew
$ brew doctor # 诊断
$ brew upgrade # 升级mac上的软件包
$ brew cleanup # 清除过时的就版本软件
$ brew list # 列出本机通过brew安装的所有软件

以安装 nginx 为例

1
2
3
4
5
6
7
$ brew search nginx #模糊搜索关键字openssl
$ brew install nginx #安装openssl
$ brew info nginx #查询openssl的安装信息
$ brew uninstall nginx #卸载openssl
$ brew uninstall --ignore-dependencies nginx #强行卸载openssl
$ brew upgrade nginx # 升级openssl,如果不加软件名,就更新所有可以更新的软件
$ brew service start|stop|restart nginx # 启动/停止/重启 nginx服务

Jenv

官网:http://www.jenv.be/

其它

清除剪切板内容
1
$ pbcopy < /dev/null
清理 DNS 缓存
1
$ sudo killall -HUP mDNSResponder;sudo killall mDNSResponderHelper;sudo dscacheutil -flushcache

推荐