• Contact
  • Contact Us
  • Disclamer
  • Home 1
  • Home 2
  • Home 3
  • Privacy Policy
Friday, May 9, 2025
How VPS - How to use/setup VPS
  • Login
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon
No Result
View All Result
How VPS - How to use/setup VPS
No Result
View All Result
Home Operating System Linux

How to Save Top Command Output to a File

How VPS by How VPS
November 2, 2018
in Linux, Operating System
0
0
SHARES
106
VIEWS
Share on FacebookShare on Twitter

Linux top command is highly used by system administrators to display system statistics in real time regarding system uptime and load average, used memory, running tasks, a summary of processes or threads and detailed information about each running process.

However, besides real time viewing of the running system, top command output can be saved to a file, by using the -b flag, which instructs top to operate in batch mode and -n flag to specify the amount of iteration the command should output.

In the below example, we’ll redirect the output of top command to top.txt file in the current working directory. The -n argument will be used to send only one snapshot of the command to the mentioned file.

$ top -b -n 1 > top.txt

To read the resulted file, use a command line file reader utility, such as cat command, less or more.

$ less top.txt
How to Save Top Command Output to a File

View Output of Top Command

To grab five iteration of top command, execute the command as shown in the below excerpt.

$ top -b -n 5 > top-5iterations.txt

In order to display only the number of running tasks from the resulted file, use the grep filter, as shown in the below command example.

$ cat top-5iterations.txt | grep Tasks
How to Save Top Command Output to a File

Show Top 5 Running Tasks

To take a snapshot of a specific process in top utility, execute command with the PID (-p) flag. To get the PID of a running process, issue pidof command against the name of the running process.

In this example we’ll monitor the cron process via top command by taking three snapshots of the PID.

$ pidof crond
$ top -p 678 -b -n3 > cron.txt
$ cat cron.txt
How to Save Top Command Output to a File

Watch Process Usage in Top Command

Using a for iteration loop, we can display a process statistics via its PID, each two seconds, as shown in the below example. The output of the loop can also be redirected to a file. We’ll use the same cron PID as shown in the above example.

$ for i in {1..4}; do sleep 2 && top -b -p 678 -n1 | tail -1 ; done	

Redirect loop output to file.

$ for i in {1..4}; do sleep 2 && top -b -p 678 -n1 | tail -1 ; done >> cron.txt
$ cat cron.txt
How to Save Top Command Output to a File

Find Linux Process Statistics

These are just a few examples on how you can monitor and gather system and process statistics via top command.

Source: tecmint.com

Tags: Linux Commandslinux guidelinux vps setup guide
Previous Post

How to Create a Password Protected ZIP File in Linux

Next Post

Gogo – Create Shortcuts to Long and Complicated Paths in Linux

Next Post

Gogo – Create Shortcuts to Long and Complicated Paths in Linux

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

No Result
View All Result

Recent Post

Install Imagemagick on CentOS
CentOS

Install Imagemagick on CentOS

by How VPS
June 28, 2023
0

This is how I installed Imagemagick on a vanilla CentOS server Start off by installing the prerequisites yum install php-pear...

Read more
how to Check phpinfo

How to Check phpinfo of Hosting or VPS?

June 28, 2023
Failed to download metadata for repo 'appstream' on Centos 8

How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

February 25, 2022
How to Fix MySQL Error "Plugin 'InnoDB' registration as a STORAGE ENGINE failed"?

How to Fix MySQL Error “Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed”?

November 17, 2020
How to optimize Mysql or MariaDB

How to optimize Mysql or MariaDB

November 3, 2020

Recent News

  • Install Imagemagick on CentOS
  • How to Check phpinfo of Hosting or VPS?
  • How to fix error: Failed to download metadata for repo ‘appstream’ on Centos 8

Category

  • Arch
  • Authentication
  • Backups
  • BSD
  • Centmin Mod
  • CentOS
  • Control Panels
  • CoreOS
  • CWP
  • Debian
  • Directadmin
  • Encryption
  • Fedora
  • Firewalls
  • Hocvps Script
  • Hosting providers
  • Kloxo-MR
  • Linux
  • Mitigations
  • Operating System
  • Plesk
  • Reviews
  • Securing VPS/Servers
  • Security Patches
  • SSL Certificates
  • Uncategorized
  • Upgrading
  • VPS/Servers management guides
  • Vulnerability Detection
  • Web servers software
  • Webhosting Control Panel
  • About
  • Advertise
  • Careers
  • Contact

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

No Result
View All Result
  • Home
  • Management guides
    • Web servers software
      • Directadmin
      • Hocvps Script
      • Centmin Mod
      • CWP
      • Kloxo-MR
      • Plesk
    • Control Panels
    • Securing VPS/Servers
      • SSL Certificates
      • Upgrading
      • Authentication
  • Operating System
    • CentOS
    • Fedora
    • Debian
    • Linux
    • Arch
    • BSD
    • CoreOS
  • Reviews
  • Coupon
    • Domain Coupon
    • Hosting Coupon

© 2025 JNews - Premium WordPress news & magazine theme by Jegtheme.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
Thabet