可用内存剩余:{`free -h | awk 'NR==2{print $4}'`} 可用缓存剩余:{`free -h | awk 'NR==2{print $6}'`} 可用虚拟内存剩余:{`free -h | awk 'NR==3{print $4}'`}
时间: 2024-05-26 18:09:58 浏览: 134
我看到你的第一个问题是关于系统内存的查询,可用内存剩余为`{free -h | awk 'NR==2{print $4}'}`,可用缓存剩余为`{free -h | awk 'NR==2{print $6}'}`,可用虚拟内存剩余为`{free -h | awk 'NR==3{print $4}'}`。是否还有其它需要帮助的地方呢?
相关问题
写一个shell脚本对free -m内存进行运算
下面是一个简单的 shell 脚本,用于计算 `free -m` 命令输出的内存使用情况:
```
#!/bin/bash
# 获取 free -m 命令输出的内容
output=$(free -m)
# 提取所需信息并进行计算
mem_total=$(echo "$output" | awk 'NR==2{print $2}')
mem_used=$(echo "$output" | awk 'NR==2{print $3}')
mem_free=$(echo "$output" | awk 'NR==2{print $4}')
mem_buffers=$(echo "$output" | awk 'NR==2{print $6}')
mem_cached=$(echo "$output" | awk 'NR==2{print $7}')
mem_available=$(echo "$output" | awk 'NR==3{print $2}')
mem_usage=$(echo "scale=2; $mem_used / $mem_total * 100" | bc)
# 输出计算结果
echo "总内存:$mem_total MB"
echo "已用内存:$mem_used MB"
echo "空闲内存:$mem_free MB"
echo "缓存内存:$mem_buffers MB"
echo "已缓存内存:$mem_cached MB"
echo "可用内存:$mem_available MB"
echo "内存使用率:$mem_usage%"
```
脚本中使用了 `awk` 命令来提取 `free -m` 命令输出的内容,并使用 `bc` 命令进行浮点数运算。运行脚本后,将会输出系统当前的内存使用情况信息。
阅读全文
相关推荐













