adr*_*lzt 24
ps ux | numfmt --header --to=iec --field 5,6 --padding 6
Run Code Online (Sandbox Code Playgroud)
你需要 coreutils >= 8.25
我个人更喜欢这个:
ps -eo pmem,comm,pid,maj_flt,min_flt,rss,vsz --sort -rss | numfmt --header --to=iec --field 4-5 | numfmt --header --from-unit=1024 --to=iec --field 6-7 | column -t | head
Run Code Online (Sandbox Code Playgroud)
中似乎没有合适的标志ps,因此您需要使用不同的工具(我个人更喜欢htop)或ps稍微弄乱输出。我猜你想坚持使用ps. 这是我制作的一个肮脏的小脚本作为示例:
# get terminal width
WIDTH=`tput cols`
# pipe stdin to awk
cat | \
awk '\
BEGIN {
# set output format
CONVFMT="%.2f"
}
NR==1 {
# search first line for columns that need to be converted from K to M
for (i=1;i<=NF;i++)
# add condition for new columns if you want
if ($i=="VSZ" || $i=="RSS") {
# column numbers are stored in an array
arr[i]=i;
$i = $i "(MB)"
}
}
NR > 1 {
# edit appropriate columns
for (i in arr)
$i=$i/1024;
}
{
# print every line
print $0
}' | \
# format the output into columns and trim it to terminal width
column -t | cut -c 1-$WIDTH
Run Code Online (Sandbox Code Playgroud)
将其保存到文件中,例如prettyps.sh,使其可执行:
chmod +x 漂亮的ps.sh
并使用如下:
ps 用户体验 | /path/to/prettyps.sh
使用这个脚本有向 ps 输出添加额外进程的缺点,但它仍然有效:
$ ps ux | ./pretyps.sh 用户 PID %CPU %MEM VSZ(MB) RSS(MB) TTY STAT 开始时间命令 波诺 2658 0.0 0.0 358.88 4.29 ? SL 02:33 0:00 /usr/bin/gnome-keyring ...输出被截断... pono 4507 0.0 0.0 19.14 1.81 pts/1 S+ 03:29 0:00 man pono 4518 0.0 0.0 10.55 0.96 pts/1 S+ 03:29 0:00 寻呼机 波诺 4727 0.7 0.9 1143.59 53.08 ? SSL 04:10 0:24 /opt/sublime_text/subl 波诺 4742 0.1 0.4 339.05 25.80 ? SL 04:10 0:03 /opt/sublime_text/plug 波诺 5177 0.0 0.0 19.23 1.32 分/0 R+ 05:05 0:00 ps 波诺 5178 0.0 0.0 4.34 0.61 pts/0 S+ 05:05 0:00 /bin/sh
希望这有助于找到适合您的方法。
| 归档时间: |
|
| 查看次数: |
21622 次 |
| 最近记录: |