11 uses of ps command in Linux

For system administrators, ps is a frequently used tool. The ps command in Linux is used to list the processes currently running on the system, with many available filtering and display modes via flags and arguments.

The syntax of ps may be strange. Normally we will follow the UNIX convention, using a single dash before each flag. So far, that syntax is most widely supported. However, the command can also be run with BSD syntax, remove the prefixed dash and use a separate flag name syntax. For example, flag aux replaces the more popular -ef flag. Make sure you know which one you're using.

How to use ps command in Linux

  1. 1. Show all processes
  2. 2. Filter by user
  3. 3. Filter by process name
  4. 4. Filter by process ID
  5. 5. Transfer the results to grep
  6. 6. Display specific columns
  7. 7. Arrange processes according to usage
  8. 8. Rename the column title
  9. 9. Display results according to hierarchical tree type
  10. 10. Display the thread inside the process
  11. 11. Show all root processes

1. Show all processes

 ps -ef 

11 uses of ps command in Linux Picture 1

The ps command displays all running processes with complete data about each process. This data includes columns showing PID, terminal type (TTY), runtime and command name.

2. Filter by user

 ps -e -u userName 

The ps command filters the results and displays only the processes owned by the specified username. This command can also be used without a prefix.

3. Filter by process name

11 uses of ps command in Linux Picture 2

 ps -C name 

The ps command on the filter results according to the process name. Search is not case sensitive, but all process names are in lowercase after filtering. The command will search through all processes without prefixes -e.

4. Filter by process ID

 ps -ef -p 1234,5678,9012 

If you know the ID of the running process you want to display, you can filter it specifically with the -p flag . This command can take multiple PIDs as arguments, separated by a comma and no spaces.

5. Transfer the results to grep

 ps -ef | grep worker 

11 uses of ps command in Linux Picture 3

If you want more flexibility when looking for results from ps, you can convert the results to grep. Although this is a combination of many commands, not just a pure ps command, it is a normal part of any administrator tool. With grep, you can search using regular expressions to find results that match the pattern and more.

6. Display specific columns

 ps -e -o pid,uname,pcpu,pmem,comm 

11 uses of ps command in Linux Picture 4

Flag -o sets the options for displaying specific output for the results of the ps command . See the full list of standard display options for ps command at https://linux.die.net/man/1/ps.

7. Arrange processes according to usage

 ps -e --sort=-pcpu -o pid,pcpu,comm 

The above syntax arranges commands according to the listed columns. The prefix minus (-) arranges the feature in descending order, while the plus (+) prefix is ​​sorted in ascending order. This command also uses the -o flag to display specific columns, not necessarily arranged.

8. Rename the column title

11 uses of ps command in Linux Picture 5

 ps -o pid=Process,ruser=RealUser,comm=Command 

When using the -o flag to create user-specified output interfaces, columns can be renamed. Add an equal sign (=) and enter the desired new name, using the -o flag for each renamed title. Titles can also be hidden in specific columns by leaving the name section blank after the equals sign. You can mix and match with name columns that are renamed and by default. Just make sure to use the -o flag for each column to be renamed as follows:

 ps -e -o pid,pcpu=CPU -o pmem=RAM,comm 

9. Display results according to hierarchical tree type

 ps -e --forest 

Use ASCII to create tree-style structures, displaying processes. The command displays the child processes of major processes and organizes the results accordingly. To hide sub-branches, use -H instead of --forest.

10. Display the thread inside the process

 ps -p 4041 -L 

11 uses of ps command in Linux Picture 6

Flag -L switch the display for every function of ps on the screen. This command is most useful when tracking threads of a particular process.

11. Show all root processes

 ps -f -U root -u root 

11 uses of ps command in Linux Picture 7

The ps command performs a search for all root processes running efficiently. This command shows them in full format thanks to the -f flag . You can combine it with the -o flag to customize the output.

Although many UNIX-style flags are more suitable for other terminal commands, BSD commands can display information in many different and sometimes more useful formats. If you are interested in learning about BSD style flags, see the following man page: https://linux.die.net/man/1/ps.

Hope you are succesful.

4.3 ★ | 3 Vote

May be interested

  • How to limit access to su command in LinuxHow to limit access to su command in Linux
    if you have added linux to your data center or are just using a single linux machine for your business, you need to make sure it is as secure as possible.
  • 12 things Linux is easier to do in the command line than graphical software12 things Linux is easier to do in the command line than graphical software
    graphical user interfaces (guis) were invented to make life easier for computer users, so it's very common to use them to perform most everyday tasks.
  • 11 df commands in Linux (with example)11 df commands in Linux (with example)
    with the df command in linux, you can easily check your system for details about disk space and file size. these 12 examples of df commands will show you how to do them in detail.
  • How to use the Linux command line on Android with TermuxHow to use the Linux command line on Android with Termux
    android is a very operating system 'capacity with more and more desktop accessibility applications. however, sometimes you want to make some things on android that can be as easy as desktop. fortunately, you can use the termux tool, which builds on the existing infrastructure and provides a command line environment that allows you to install real linux applications on your android device.
  • Instructions for using find command in LinuxInstructions for using find command in Linux
    the find command is one of the most important and handy commands on a linux system. as its name suggests, the command can find files on a linux pc based on a variety of conditions and variables you set.
  • How to use the history command in LinuxHow to use the history command in Linux
    as you spend more and more time in terminal sessions, you will constantly find new commands that make everyday tasks more efficient. the gnu history command is one of them.
  • Instructions for using pstree command on LinuxInstructions for using pstree command on Linux
    pstree is a powerful and useful command to display processes running in linux. like the ps command, it shows all the processes that are currently active on your login system. the main difference is that when running the pstree command, processes are organized into tree sorting instead of lists like using the ps command.
  • The dd command in Linux, How to use the dd commandThe dd command in Linux, How to use the dd command
    dd is a command line utility for unix-like and unix operating systems, with the main purpose of converting and copying files.
  • Use the Top command to see the processes running in LinuxUse the Top command to see the processes running in Linux
    the top command in linux is used to display all processes running in the linux environment. this tutorial shows you how to use the top command through explaining the various parameters available and the content they display.
  • How to use the dmesg command in LinuxHow to use the dmesg command in Linux
    the dmesg command has been used to troubleshoot server and linux desktops for decades. it's time to start using this handy command!