Linux 常用

系统信息


查看CPU信息(型号)
cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
 
查看物理CPU个数
cat /proc/cpuinfo | grep "physical id" | sort | uniq | wc -l
 
查看每个物理CPU中core的个数(即核数)
cat /proc/cpuinfo | grep "cpu cores" | uniq
 
查看逻辑CPU的个数
cat /proc/cpuinfo | grep "processor" | wc -l

free

显示内存使用信息
free 
 
以总和的形式查询内存的使用信息
free -t
 
每10s 执行一次命令
free -s 10

free

cpu 排序
ps -aux --sort -pcpu | less
 
内存排序
ps -aux --sort -pmem | less
 
cpu和内存,管道显示前10个结果
ps -aux --sort -pcpu,+pmem | head -n 10
 
通过进程名和PID过滤
ps -f -C getty
 
特定进程的线程
ps -L 1213
 
树形结构显示进程
ps -axjf
pstree
 
组合 ps 和 watch
watch -n 1 ‘ps -aux --sort -pmem, -pcpu’
 

 top

显示完整命令
top -c
 
设置信息更新次数
top -n 2            //表示更新两次后终止更新显示
 
设置信息更新时间
top -d 3            //表示更新周期为3秒
 
显示指定的进程信息
top -p 139          //显示进程号为139的进程信息,CPU、内存占用率等 

cat

反向为cat 
tac
 
查看大文件通过more或者less翻页
cat test4.txt | more
cat test4.txt | less
 
查看文件内容展示行号
cat -n test4.txt
 
查看文件行的末尾
cat -e test4.txt        //$突出显示每行的末尾和行之间的空格
 
查看制表符行
cat -t test4.txt
 
查看省略空白行
cat -s test4.txt        //删除空白行
 
重定向标准输入


cat < test1.txt
使用cat、tail、head组合
1、cat filename | tail -n 100                     查看最后100行的数据
2、cat filename | head -n 300 | tail -n +100      查看100到300行的数据
3、cat filename                                   打印文件所有内容
4、cat filename tail -n 100                       打印文件最后100行的数据
5、cat filename head -n 100                       打印前100的内容  

空间

磁盘
df -h
 
查看根目录是否有大文件
cd / && du -sh * 
 
查看哪个目录占用过高
cd / && du -h -x --max-depth=1
 
 
lsblk  磁盘结构

目录

查看当前文件目录各个文件夹大小
du -h --max-depth=1
 
查看指定目录
du -h --max-depth=1 /path
 
查看当前目录下所有目录及子目录大小
du -h - .

jstack 

通过jstack -l pid 命令输出dump信息
# l参数表示输出长列表信息,如关于锁的附加信息
jstack -l 8888 > stack_8888.dump


1.死锁,Deadlock
2.执行中,Runnable
3.等待资源,Waiting on condition
4.等待获取监视器,Waiting on monitor entry
5.暂停,Suspended
6.对象等待中,Object.wait()或TIMED_WAITING
7.阻塞,Blocked
8.停止,Parked

你可能感兴趣的:(linux,运维,服务器)