Linux top command, top command in Linux/UNIX.

Top command in Linux and Unix is used to display the Linux Process. The Linux top command program provides a dynamic real-time view of a running system. Also, display the system summary information as well as a list of processes or threads currently being managed by the Linux kernel.

So we will discuss the top command in detail if you want to learn about the output of the top command explained refer the link.

UNIX/LINUX top command cheat sheet
Linux top command run once.

Syntax:
# top -n [iteration]

Command:
# top -n 1
Linux top command sort by Memory/Memory Usage.

Syntax:
# top -o [Field]

Command:
# top -o %MEM
# On top Screen 
"press Shift + m" or "press M"
Linux top command sort by CPU/CPU Usage.

Syntax:
# top -o [Field]

Command:
# top -o %CPU
# On top Screen 
"press Shift + p" or " press P"
Linux top command sort by user.

Syntax:
# top -o [Field]

Command:
# top -o USER
# On top Screen 
"press shift + r"
Linux top command sort by TIME.
Syntax:
# top -o [Field]

Command:
# top -o TIME
# On top Screen 
"press Shift + t" or "press T"
Linux top command sort by process id/PID.

Syntax:
# top -o [Field]

Command:
# top -o PID
# On top Screen 
"press Shift + n" or "press N"
top command monitors the specific process or PID.

Syntax:
# top -p[pid1,pid2...pidN]

Command:
# top -p1,2,3,4,5,7,8,9,10
Linux top command filter by Process ID.

Command:
# On top Screen
STEP 1: "pressing shift + o" and get the prompt 
add filter #1 (case sensitive) as: [!]FLD?VAL PID<10
STEP 2: "Press Enter"
Linux top command filter by Name.

Command:
# On top Screen
STEP 1: "pressing shift + o" and get the prompt 
add filter #1 (case sensitive) as: [!]FLD?VAL USER=tla
STEP 2: "Press Enter"
Linux top command filter by Process name.

Command:
# On top Screen
STEP 1: "pressing shift + o" and get the prompt 
add filter #1 (case sensitive) as: [!]FLD?VAL COMMAND=nginx
STEP 2: "Press Enter" 
Linux top command delay time/ run top command every 5 minutes.

Syntax:
# top -d [delay time]

Command:
# top -d 300
# On top Screen 
STEP 1: "press d" and the prompt will be 
"Change delay from 3.0 to"300
STEP 2: "press Enter"
Linux top command show memory in GB.

Syntax:
# top -E [k | m | g | t | p | e]

Command:
# top -E g
# On top Screen
"press e"
Linux top command thread view.

Command:
# top -H
Linux top highlight process.

Command:
# On top Screen
"press z"
Linux top process tree.

Command:
# On top Screen
"press V" or "press Shift + v"
Linux top command full absolute path.

Command:
# top -c
# On top Screen
"press c"
Kill the process using top command.

Command:
# On top Screen
 STEP 1: "press k" it will prompt like 
"PID to signal/kill [default pid = 1234]": "Enter the PID" and "press enter"
STEP 2: Again it will prompt to 
"Send PID 1225 signal [15/sigterm]": "press enter to kill".
Linux top command graphical mode.

Command:
# On top Screen
For CPU "press t".
For Memory "press m".
top command Add fields/Add column.

Command:
# On top Screen
STEP 1: "pressing f" or "Shift +F"
STEP 2: "press SPACE" to select the fields.
STEP 3: "Press q" and check in the top Screen
top command running tasks/Active Process.

Command:
# On top Screen 
"press i"
top 10 process/limit rows top command output.

Command:
# On top Screen
 STEP 1: "press n" it will prompt 
"Maximum tasks = 0, change to (0 is unlimited)"10
STEP 2: After putting 10 "press Enter"

Linux/UNIX top command run once

If we want to run the top command once we will use -n option with the command.

# top -n 1

So, this will run the top command only once and make the exit, what if want to run the command 10 times and then exit.

Linux top command, top command in Linux/UNIX.
# top -n 10

So this will perform 10 iterations with the top command by using -n option.

Linux/UNIX top command sort by memory, user, CPU, memory usage, CPU usage, process id, PID, TIME.

— top command sort by Memory/Memory Usage.

So, we will sort the process by Memory or by Memory Usage, so there are many options to do the sorting.

# top -o %MEM

So here we have used -o option with the top command for the sorting of Memory by using %MEM.

Also, we can “press Shift + m” or “press M” to sort by Memory or Memory usage in top command.

Linux top command, top command in Linux/UNIX.

— top command sort by CPU/CPU Usage.

For sorting by CPU we will use -o option with %CPU, also we can check the usage of CPU

# top -o %CPU

Also, we can “press Shift + p” or ” press P” to sort the top command by CPU or CPU usage.

Linux top command, top command in Linux/UNIX.

— top command sort by User.

To sort User by top command use -o option with USER field, let’s look at the command below.

# top -o USER

we can also use “press shift + r” or “press R” to check the user or any field in reverse order.

— top command sort by time.

So now we will sort the time with the top command by using -o option.

# top -o TIME

When you are on the top screen then you can “press Shift + t” or “press T” with that you can sort by time.

Linux top command, top command in Linux/UNIX.

— top command sort by Process id/PID.

Process id and the PID are the same, so with the top command, we will use -o option and PID as an argument.

Linux top command, top command in Linux/UNIX.
# top -o PID
Linux top command, top command in Linux/UNIX.

So you can also check on the top screen by “pressing Shift + n” or “Press N” this will sort by process id.

Linux top command, top command in Linux/UNIX.

Top command monitor specific process or PID.

So we have to monitor the process id 1, 2, 3, 5, 7, 8, 9, and 10 here we will use -p option.

Linux top command, top command in Linux/UNIX.
# top -p1,2,3,4,5,7,8,9,10
Linux top command, top command in Linux/UNIX.

So this will monitor only the specific process id with -p option

Linux top command, top command in Linux/UNIX.

To monitor a specific user we will use grep command refer to link to learn about grep command

# top |grep tla 

So tla is the user which we have grep from the top command and it will show the process of tla user.

top command filter by user, process name, Process ID, USER.

So to filter the user, process name, ID, and CPU on the top screen, we will “press shift + o” or “press O”.

— top command filter by Process ID.

So after “pressing shift + o” you will get the prompt “add filter #1 (case sensitive) as: [!]FLD?VAL”

Linux top command, top command in Linux/UNIX.

The FLD is the field name and VAL is the value, let’s see the example.

add filter #1 (case sensitive) as: [!]FLD?VAL PID<10

So, this will show the PID which will be less than 10, you can “use =(equal), or >(greater than)” with the PID.

So we got the PID which is less than 10, now we will see a specific User by “pressing shift + o”.

— top command filter by Name.

add filter #1 (case sensitive) as: [!]FLD?VAL USER=tla

So USER is our field and tla is the user that we have to filter out.

you can also use -u option with top command to filter the specific User.

# top -u mysql

By using this command we can see the running process of mysql User.

— top command filter by Process name.

Suppose the Nginx process is running on the server and we have to monitor Nginx Process only.

add filter #1 (case sensitive) as: [!]FLD?VAL COMMAND=nginx

So, we have filtered by Process Name and the COMMAND is the field on the top screen.

Linux/UNIX top command delay time/ run top command every 5 minutes.

The top command delay time is the time when it refresh the top screen.

So we will use -d option or we will simply “press d” on the top screen to set the delay time in top command.

# top -d 2

So -d option will refresh the top screen by 2 seconds, let’s see the option by “pressing d” on the top screen.

Hereby default the screen refresh interval at every 3 seconds by “pressing d” it will prompt “Change delay from 3.0 to”, So we have to display in every 1 second.

So we have put 1 on the top screen then the refresh interval of the top screen will at every 1 second.

Now we will have to run the top command every 5 minutes, so as we know it takes the input in seconds.

So, for 5 minutes we will use 300 seconds, let’s see with the command.

# top -d 300
"press d" and the prompt will be "Change delay from 3.0 to" 300

Linux/UNIX top command show memory in GB.

So here there are two options use -E option which is Extended Memory Scaling, it will show the RAM size in Human readable format.

Other option by “pressing e” on the top screen, let’s see the commands.

# top -E g

So this will show the RAM size in GB, as below screenshot.

Let’s “press e” option inside the top screen for the Extended Memory Scaling.

Linux/UNIX top command thread view.

So if we have to display the individual threads use -H option with top command.

# top -H

So in the place of “Tasks” it will display the “Threads” on the top screen.

There are total number of threads are 407 and 1 running threads.

Linux/UNIX top highlight process.

So, to highlight the running process in top command we will “press z” on the top screen.

Linux/UNIX top process tree.

So to view the sub process of the processes known as “Forest View Mode”.

We have to “press V” or “press Shift + v” to view the subprocess in the COMMAND field.

Linux/UNIX top command full absolute path.

So to check the full absolute path “press c on the top screen, or use the option -c.

# top -c

So by using -c or by “pressing c” we can see the full path of the process.

kill the process using top command.

So to kill the process by using top command “press k” and it will prompt like “PID to signal/kill [default pid = 1234]”.

Then “Enter the PID” and “press enter”, so it will prompt “Send PID 1225 signal [15/sigterm]” then press enter to kill.

So it will send the process termination signal to the kernel and that will terminate the process.

So to see the CPU and Memory in graphical mode “press t” and “press m”.

You can see the BAR instead of TEXT in the Memory and CPU.

top command Add fields/Add column.

So in the top command, you can Mange the fields by “pressing f” or “Shift +F” on the top screen.

Now we will select PPID and UID fields from the filed Management Window and use s to sort the fields.

So here we will sort by %CPU and we press SPACE to select the PPID and UID fields.

Now we will press q command and check the top screen with the two field.

top command running tasks/Active Process.

So to check the Active process with top command, “press i(small i)” to check the running task.

top 10 process/limit rows top command output.

If we want to see the top 12 processes “press n” it will prompt like “Maximum tasks = 0, change to (0 is unlimited)” then just put 12 as we want to see the top 12 processes.

So, after “pressing Enter” can see the top 12 processes running on the top command screen.

Now suppose we want to see the top 10 processes than “press n” it will prompt like “Maximum tasks = 0, change to (0 is unlimited)” and write 10 and “press Enter”.

So it will display the top 10 Process in the top command. The same steps to be followed to limit the row in top command.

The Top command output explained into another post please refer the POST to learn detail about the TOP command.

Give your valuable time