Created
June 4, 2020 12:58
-
-
Save valter-jnr/03603e71f80ca74977dc13e65b4f5de4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
You could use the -o switch to specify your output format: | |
$ ps -eo args | |
From the man page: | |
Command with all its arguments as a string. Modifications to the arguments may be shown. [...] | |
You may also use the -p switch to select a specific PID: | |
$ ps -p [PID] -o args | |
pidof may also be used to switch from process name to PID, hence allowing the use of -p with a name: | |
$ ps -p $(pidof dhcpcd) -o args | |
Of course, you may also use grep for this (in which case, you must add the -e switch): | |
$ ps -eo args | grep dhcpcd | head -n -1 | |
GNU ps will also allow you to remove the headers (of course, this is unnecessary when using grep): | |
$ ps -p $(pidof dhcpcd) -o args --no-headers | |
On other systems, you may pipe to AWK or sed: | |
$ ps -p $(pidof dhcpcd) -o args | awk 'NR > 1' | |
$ ps -p $(pidof dhcpcd) -o args | sed 1d | |
Edit: if you want to catch this line into a variable, just use $(...) as usual: | |
$ CMDLINE=$(ps -p $(pidof dhcpcd) -o args --no-headers) | |
or, with grep : | |
$ CMDLINE=$(ps -eo args | grep dhcpcd | head -n -1) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment