Skip to content
TheChatArchiveThe Chat Archive
o3-mini· OpenAIHugging Face LMArena Human Preference 140K

echo "CPU: $(top -bn1 grep "Cpu(s)" awk '{print $2 + $4}')% RAM: $(free -m awk…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Qwenqwen-max-2025-01-25’s answer.
  1. User

    echo "CPU: (top -bn1 | grep "Cpu(s)" | awk '{print 2 + 4}')% RAM: (free -m | awk '/Mem/{printf("%.2f%"), 3/3/2*100}')"

  2. Assistant

    This one-liner combines several commands to quickly display a summary of the system’s CPU and RAM usage. Here’s a breakdown of what each part does:

    1. CPU Usage Calculation:

      • top -bn1
        Runs top in batch mode (-b) for a single iteration (-n1), which outputs a snapshot of system processes and CPU information.

      • grep "Cpu(s)"
        Filters the output to only include the line containing CPU usage statistics.

      • awk '{print $2 + $4}'
        Processes the filtered line and adds the values in the second and fourth fields.
        Note: Depending on your version and configuration of top, these fields typically correspond to the percentage of CPU in user mode (often in the second field) and the percentage in system mode (often in the fourth field). The sum gives an approximation of the actively used CPU (user + system).

    2. RAM Usage Calculation:

      • free -m
        Displays memory usage in megabytes.

      • awk '/Mem/{printf("%.2f%"), $3/$2*100}'
        Looks for the line starting with “Mem” and calculates the percentage of used memory by dividing the used memory ($3) by the total memory ($2) and then multiplying by 100. The result is formatted to two decimal places and appended with a % sign.

    3. Putting It All Together:

      • The outer echo command combines these two parts into a single formatted string:
        CPU: <calculated_value>% RAM: <calculated_value>
        

    When you run this command in a Linux terminal, it will output something similar to:

    CPU: 17.2% RAM: 57.35%
    

    Keep in mind:

    • The actual CPU line formatting from top may vary between different systems, so the field positions used in the awk command might need adjustment for your particular environment.
    • This command is intended for Linux systems where these tools (top, free, awk, and grep) are available.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.