What is the usage of the top command in Ubuntu?
In Ubuntu, the top command is used to view the system’s running status and process information in real-time. This command displays a list of currently running processes and sorts them based on metrics like CPU usage, memory usage, etc.
Here are some common options and usages of the top command.
- To run the top command directly:
Simply type “top” and press Enter, and it will display a list of processes on the current system, sorted by default in descending order of CPU usage. - Exit the top command by pressing the “q” key on the keyboard.
- Switch process sorting method:
While running the top command, pressing the M key on the keyboard will sort by memory usage, and pressing the P key will sort by CPU usage. - To display the processes of a specific user, use the command top -u username to show only the processes of the specified username.
- Display a specific number of processes:
By entering the command top -n number, only the specified number of processes will be displayed, by default all processes are shown. - Run the top command in batch mode by entering the top -b command, which will output the results to the standard output stream.
- To update the display at specified intervals:
By entering the command top -d seconds, the display will be updated at the specified time interval (in seconds), with the default being 3 seconds. - To display the full path, enter the top -c command, which will show the full path of the process command.
Here are some common options and usages of the top command, you can choose the appropriate options as needed to use the top command.