Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
交换命令:/usr/sbin/swap -s
/usr/sbin/swap -s
我什至尝试过类似的东西,awk '/total/ {print $2}' /usr/sbin/swap -s但给了我错误
awk '/total/ {print $2}' /usr/sbin/swap -s
交换输出:
total: 12417784k bytes allocated + 2705800k reserved = 15123584k used, 45459976k available
我需要分别获得used一个available值,即15123584k和45459976k。
used
available
15123584k
45459976k
使用管道将输出传递swap到awk
swap
awk
/usr/sbin/swap -s | awk '/total/ {print $2}'
为了得到 and 的值15123584k,45459976k我们使用打印出第 9 列和第 11 列
/usr/sbin/swap -s | awk '/total/ {print $9" "$11}'