The **[Linux Top command][1]** is the best and most well known command that everyone uses to **[monitor Linux system performance][2]**.
You probably already know most of the options available, except for a few options, and if I’m not wrong, “batch more” is one of the options.
Most script writer and developers know this because this option is mainly used when writing the script.
If you’re not sure about this, don’t worry we’re here to explain this.
### What is “Batch Mode” in the Top Command
The “Batch Mode” option allows you to send top command output to other programs or to a file.
In this mode, top will not accept input and runs until the iterations limit you’ve set with the “-n” command-line option.
If you want to fix any performance issues on the Linux server, you need to **[understand the top command output][3]** correctly.
### 1) How to Run the Top Command in Batch Mode
By default, the top command sort the results based on CPU usage, so when you run the below top command in batch mode, it does the same and prints the first 35 lines.
```
# top -bc | head -35
top - 06:41:14 up 8 days, 20:24, 1 user, load average: 0.87, 0.77, 0.81
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
18105 mysql 20 0 1453900 156888 8816 S 0.0 4.0 2:16.42 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
```
### 4) How to Run the Top Command in Batch Mode and Sort the Output Based on the Process Age
Use the below top command to sort the results based on the age of the process in batch mode. It shows the total CPU time the task has used since it started.
But if you want to check how long a process has been running on Linux, go to the following article.
* **[Five Ways to Check How Long a Process Has Been Running in Linux][4]**
```
# top -bc -o TIME+ | head -n 20
top - 06:45:56 up 8 days, 20:28, 1 user, load average: 0.56, 0.77, 0.81
In the latest version of the top command release, press the **“f”** key to sort the fields via the field letter.
To sort with a new field, use the **“up/down”** arrow to select the correct selection, and then press **“s”** to sort it. Finally press **“q”** to exit from this window.
```
Fields Management for window 1:Def, whose current sort field is %CPU
Navigate with Up/Dn, Right selects for move then or Left commits,
'd' or toggles display, 's' sets sort. Use 'q' or to end!
PID = Process Id nsUTS = UTS namespace Inode
USER = Effective User Name LXC = LXC container name
PR = Priority RSan = RES Anonymous (KiB)
NI = Nice Value RSfd = RES File-based (KiB)
VIRT = Virtual Image (KiB) RSlk = RES Locked (KiB)
RES = Resident Size (KiB) RSsh = RES Shared (KiB)
SHR = Shared Memory (KiB) CGNAME = Control Group name
S = Process Status NU = Last Used NUMA node
%CPU = CPU Usage
%MEM = Memory Usage (RES)
TIME+ = CPU Time, hundredths
COMMAND = Command Name/Line
PPID = Parent Process pid
UID = Effective User Id
RUID = Real User Id
RUSER = Real User Name
SUID = Saved User Id
SUSER = Saved User Name
GID = Group Id
GROUP = Group Name
PGRP = Process Group Id
TTY = Controlling Tty
TPGID = Tty Process Grp Id
SID = Session Id
nTH = Number of Threads
P = Last Used Cpu (SMP)
TIME = CPU Time
SWAP = Swapped Size (KiB)
CODE = Code Size (KiB)
DATA = Data+Stack (KiB)
nMaj = Major Page Faults
nMin = Minor Page Faults
nDRT = Dirty Pages Count
WCHAN = Sleeping in Function
Flags = Task Flags
CGROUPS = Control Groups
SUPGIDS = Supp Groups IDs
SUPGRPS = Supp Groups Names
TGID = Thread Group Id
OOMa = OOMEM Adjustment
OOMs = OOMEM Score current
ENVIRON = Environment vars
vMj = Major Faults delta
vMn = Minor Faults delta
USED = Res+Swap Size (KiB)
nsIPC = IPC namespace Inode
nsMNT = MNT namespace Inode
nsNET = NET namespace Inode
nsPID = PID namespace Inode
nsUSER = USER namespace Inode
```
For older version of the top command, press the **“shift+f”** or **“shift+o”** key to sort the fields via the field letter.
To sort with a new field, select the corresponding sort **field letter**, and then press **“Enter”** to sort it.
```
Current Sort Field: N for window 1:Def
Select sort field via field letter, type any other key to return