xargs -0a /proc/27288/cmdline echo

Show the command line for a PID, converting nulls to spaces and a newline

If you cat the file, all the parts of the command line are bunched up. If you use tr to convert the nulls to spaces, you're still left without a newline unless you add another step. This command does everything for you.
Sample Output
/usr/lib/postgresql/9.3/bin/postgres -D /var/lib/postgresql/9.3/main -c config_file=/etc/postgresql/9.3/main/postgresql.conf

7
By: dennisw
2015-09-25 17:35:11

2 Alternatives + Submit Alt

What Others Think

Very nice, especially if you combine it with "pgrep -n" - find most recent match: xargs -0a /proc/$(pgrep -n rsync)/cmdline echo
flatcap · 138 weeks and 2 days ago
This is the same as the ps command we figured out yesterday, isn't it? ps h -o %a 21679
BeniBela · 138 weeks and 2 days ago
@benibela: Yes, you're right. Quick post a new command...
flatcap · 138 weeks and 1 day ago
No it's not the same because the ps command will still show only up to the length of your terminal. I have not been able to get it to ignore that (similar to what -l with systemctl/journalctl does).
Tatsh · 138 weeks and 1 day ago
@tatsh: You can add a couple of w's (wide) to ps to make ps show the entire command line: ps wwh -o %a 21679
flatcap · 138 weeks ago
Nice! I wrapped it in a function for easier use: function cmdline { xargs -0a /proc/${1:-$$}/cmdline echo; } cmdline 1234
robinsonaarond · 137 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: