I need to write the script for displaying swap utilisation in top command, I am able to display top command but next shift+f needed to be included in script can you guys help me here

1 Answer 1


If you just need the swap-usage for a script, I would use free.

# free -m
# free -m|grep Swap|awk '{print $3}'

The first command list memory and swap usage in MB. The second command gives you the used swap also in MB.

  • 1
    grep Swap|awk '{print $3}' is better written as awk '/Swap/ { print $3 }'.
    – Kusalananda
    Aug 4, 2021 at 8:07
  • It’s not entirely clear what the question author was looking for, based on their reaction to this answer; but top’s swap display, as accessed through Shift-F and adding the “SWAP” column, shows per-process swap information, not the overall swap use (which is accessible directly at the top of the top display). Aug 4, 2021 at 12:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .