Linux命令备份
发表于: 2022-08-19 18:54:25
简介: shell
df 命令(磁盘相关)
报告文件系统磁盘空间的使用情况
-h 人类可读
–human-readable,用人类可读的格式(也就是常见的格式)显示出大小(例如:1K 234M 2G)
[root@VM-12-2-centos node]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 1.9G 508K 1.9G 1% /run
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/vda1 79G 48G 28G 64% /
tmpfs 374M 0 374M 0% /run/user/0
[root@VM-12-2-centos node]#
-l 本地文件
–local,只显示本地文件系统使用状况
[root@VM-12-2-centos node]# df -l
文件系统 1K-块 已用 可用 已用% 挂载点
devtmpfs 1897644 0 1897644 0% /dev
tmpfs 1912952 0 1912952 0% /dev/shm
tmpfs 1912952 508 1912444 1% /run
tmpfs 1912952 0 1912952 0% /sys/fs/cgroup
/dev/vda1 82503044 50073552 28973988 64% /
tmpfs 382588 0 382588 0% /run/user/0
[root@VM-12-2-centos node]#
du 命令(磁盘相关)
du(Disk Usage) - 报告磁盘空间使用情况
–max-depth 指定深度
查看当前目录下的,所有文件和目录
[root@VM-12-2-centos node]# du --max-depth=1
864 ./billd-ui
8276 ./react18-blog-client
255912 ./vue3-blog-server
561524 ./nuxt-blog-client
28400 ./billd-live-server
8292 ./react17-webpack5-template
2820 ./vue3-blog-admin
2412 ./overview
4347136 ./backups
5328 ./netease-cloud-music
8228 ./vue3-webpack5-template
201420 ./netease-cloud-music-api
44 ./sh
232 ./multi-env-project
429600 ./next-blog-client
56 ./lang
972 ./billd-monorepo
5919556 .
[root@VM-12-2-centos node]#
-h 人类可读
[root@VM-12-2-centos node]# du --max-depth=1 -h
864K ./billd-ui
8.1M ./react18-blog-client
250M ./vue3-blog-server
549M ./nuxt-blog-client
28M ./billd-live-server
8.1M ./react17-webpack5-template
2.8M ./vue3-blog-admin
2.4M ./overview
4.2G ./backups
5.3M ./netease-cloud-music
8.1M ./vue3-webpack5-template
197M ./netease-cloud-music-api
44K ./sh
232K ./multi-env-project
420M ./next-blog-client
56K ./lang
972K ./billd-monorepo
5.7G .
[root@VM-12-2-centos node]#
-s 总和
–summarize, 对每个参数只显示总和。
[root@VM-12-2-centos node]# du -s
5919556 .
[root@VM-12-2-centos node]# du -s -h
5.7G .
[root@VM-12-2-centos node]#
-m 兆字节
–megabytes,输出以兆字节的块为计数单位的大小(就是 1,048,576 字节)。
[root@VM-12-2-centos node]# du -s -m
5781 .
[root@VM-12-2-centos node]# du -s -m -h
5.7G .
[root@VM-12-2-centos node]#
free 命令(内存相关)
-h 人类可读
[root@VM-12-2-centos node]# free -h
total used free shared buff/cache available
Mem: 3.6Gi 2.8Gi 127Mi 1.0Mi 709Mi 548Mi
Swap: 4.0Gi 341Mi 3.7Gi
[root@VM-12-2-centos node]#
-m 单位为 M
-m 显示内存的单位为 M
[root@VM-12-2-centos node]# free -m
total used free shared buff/cache available
Mem: 3736 2899 131 1 704 548
Swap: 4095 341 3754
[root@VM-12-2-centos node]#
-k 单位为 KB
-k 显示内存的单位为 KB
[root@VM-12-2-centos node]# free -k
total used free shared buff/cache available
Mem: 3825904 2969488 130172 2040 726244 561092
Swap: 4194300 349972 3844328
[root@VM-12-2-centos node]#
-s 轮训
-s<时间> 每隔指定时间执行一次命令,单位为 s
[root@VM-12-2-centos node]# free -h -s 1
total used free shared buff/cache available
Mem: 3.6Gi 2.8Gi 125Mi 1.0Mi 709Mi 546Mi
Swap: 4.0Gi 341Mi 3.7Gi
total used free shared buff/cache available
Mem: 3.6Gi 2.8Gi 127Mi 1.0Mi 709Mi 549Mi
Swap: 4.0Gi 341Mi 3.7Gi
total used free shared buff/cache available
Mem: 3.6Gi 2.8Gi 126Mi 1.0Mi 709Mi 548Mi
Swap: 4.0Gi 341Mi 3.7Gi
^C
[root@VM-12-2-centos node]#
-c 打印次数
-c 重复打印几次后退出
[root@VM-12-2-centos node]# free -h -s 1 -c 3
total used free shared buff/cache available
Mem: 3.6Gi 2.8Gi 125Mi 1.0Mi 709Mi 546Mi
Swap: 4.0Gi 341Mi 3.7Gi
total used free shared buff/cache available
Mem: 3.6Gi 2.8Gi 123Mi 1.0Mi 709Mi 545Mi
Swap: 4.0Gi 341Mi 3.7Gi
total used free shared buff/cache available
Mem: 3.6Gi 2.8Gi 124Mi 1.0Mi 709Mi 545Mi
Swap: 4.0Gi 341Mi 3.7Gi
[root@VM-12-2-centos node]#
# 普通free
free
# 用mb显示
free -m
# 用byte显示
free -b
# 更友好的显示
free -h
#每隔一秒输出一次
free -s 1
#每隔一秒友好输出一次
free -hs 1
ls 命令(文件相关)
-a
–all,不隐藏任何以. 开始的项目
[root@VM-12-2-centos billd-ui]# ls -a
. .. 404.html assets component index.html logo.png theme
[root@VM-12-2-centos billd-ui]#
-A
–almost-all,列出除. 及… 以外的任何项目
[root@VM-12-2-centos billd-ui]# ls -A
404.html assets component index.html logo.png theme
[root@VM-12-2-centos billd-ui]#
-l
使用较长格式列出信息
[root@VM-12-2-centos billd-ui]# ls -l
总用量 40
-rw-r--r-- 1 root root 2395 2月 23 13:06 404.html
drwxr-xr-x 5 root root 4096 2月 23 13:06 assets
drwxr-xr-x 5 root root 4096 2月 23 13:06 component
-rw-r--r-- 1 root root 5986 2月 23 13:06 index.html
-rw-r--r-- 1 root root 13178 2月 23 13:06 logo.png
drwxr-xr-x 2 root root 4096 2月 23 13:06 theme
[root@VM-12-2-centos billd-ui]#
-h 人类可读
[root@VM-12-2-centos billd-ui]# ls -l -h
总用量 40K
-rw-r--r-- 1 root root 2.4K 2月 23 13:06 404.html
drwxr-xr-x 5 root root 4.0K 2月 23 13:06 assets
drwxr-xr-x 5 root root 4.0K 2月 23 13:06 component
-rw-r--r-- 1 root root 5.9K 2月 23 13:06 index.html
-rw-r--r-- 1 root root 13K 2月 23 13:06 logo.png
drwxr-xr-x 2 root root 4.0K 2月 23 13:06 theme
[root@VM-12-2-centos billd-ui]#
ps 命令(进程相关)
ps (英文全拼:process status)命令用于显示当前进程的状态,类似于 windows 的任务管理器。
ps 有很多选项。在支持SUS和POSIX标准的操作系统上,ps 常以选项**-ef运行,其中“-e”选择每一个(every)进程,“-f”指定“完整”(full)输出格式。这些系统上的另一个常见选项是-l**,它指定“长”(long)输出格式。
-A 所有进程
显示所有进程。
[root@VM-12-2-centos node]# ps -A
PID TTY TIME CMD
1 ? 00:00:06 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 rcu_gp
4 ? 00:00:00 rcu_par_gp
-e 所有进程
显示所有进程。约等于 -A
[root@VM-12-2-centos node]# ps -e
PID TTY TIME CMD
1 ? 00:00:06 systemd
2 ? 00:00:00 kthreadd
3 ? 00:00:00 rcu_gp