blog
blog copied to clipboard
Linux 常用工具
trafficstars
htop
htop 可以查看目前的内存、CPU 使用情况
ncdu 与 du -sh
- ncdu 可以查看当前目录下各个目录的大小 ncdu --exclude 可以排除某个文件
- du -sh + 路径名,可以查看路径目录/文件的大小
硬件时间与系统时间
- hwclock # 查看硬件时间
- hwclock --hctosys # 硬件时间与系统时间同步
可以 install ntp,然后修改 /etc/ntp.conf ,设置自己的 time-server
ls
- ls -al -t # 按修改时间排序
- ls -al -c # 按创建时间排序
- ls -al -u # 按访问时间排序
加上 -r 即可逆序
- ls -l | grep ^- 当前目录下的文件
- ls -l | grep ^d 当前目录下的文件夹
- ls -al -t | head -10 按修改时间排序后选择前 10 个
- ls -al -t | tail -10 按修改时间排序后选择后 10 个
find
- find . -type d -name 'test' # 递归找到当前目录下以 test 开头的目录
- find . -type f -name 'test' # 递归找到当前目录下以 test 开头的文件
- find . -mtime +2 -type f # 递归找到当前目录下,修改时间为 2 天前的文件
dig
- MX 记录查询
root@server:~# dig csdn.net MX +noall +answer
or
root@server:~# dig -t MX csdn.net +noall +answer
# 后者`-t`代表查询类型,可以是`A`,`MX`,`NS`等,`+noall` 代表清除所有显示的选项
输出:
root@pelin:~# dig -t MX csdn.net +noall +answer
; <<>> DiG 9.9.5-3ubuntu0.13-Ubuntu <<>> -t MX csdn.net +noall +answer
;; global options: +cmd
csdn.net. 599 IN MX 10 mxbiz2.qq.com.
csdn.net. 599 IN MX 5 mxbiz1.qq.com.
可以看到,csdn.net 的 MX 记录可能是用的腾讯企业邮。
- NS 记录
root@pelin:~# dig -t NS csdn.net +noall +answer
输出:
root@pelin:~# dig -t NS csdn.net +noall +answer
; <<>> DiG 9.9.5-3ubuntu0.13-Ubuntu <<>> -t NS csdn.net +noall +answer
;; global options: +cmd
csdn.net. 21599 IN NS ns4.dnsv3.com.
csdn.net. 21599 IN NS ns3.dnsv3.com.
可以看到,csdn.net 用的是 dnspod 的解析
traceroute 与 mtr
traceroute 就是个路由跟踪的工具,使用: traceroute www.baidu.com mtr 是一个对 traceroute 的优化,使用:mtr www.baidu.com
MySQL 远程执行语句
$ mysql -s -h $MYSQL_HOST -D $DATABASE -uroot -p123456 -e "SQL 语句" > list
-s 获得极少的输出
SHA1
Linux/UNIX 系统可以通过 openssl 工具类来对字符串做 SHA1 加密
$ echo -n "test" | openssl dgst -sha1 | awk '{print $2}'
查看版本号
- 查看内核版本号:
root@pelin:~# cat /proc/version
Linux version 3.13.0-116-generic (buildd@lcy01-03) (gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3) ) #163-Ubuntu SMP Fri Mar 31 14:13:22 UTC 2017
root@pelin:~# uname -r
3.13.0-116-generic
root@pelin:~# uname -a
Linux pelin 3.13.0-116-generic #163-Ubuntu SMP Fri Mar 31 14:13:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
- 查看发行版版本号
root@pelin:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 14.04.5 LTS
Release: 14.04
Codename: trusty
root@pelin:~# cat /etc/issue
Ubuntu 14.04.5 LTS \n \l