ps grep with header

psg () { ps auxwww | egrep "$1|PID" | grep -v grep }
Yet another ps grep function, but this one includes the column headings.
Sample Output
$ psg X
USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root      5638  3.2  5.4  73244 56460 tty7     Ss+   2008 2416:47 /usr/X11R6/bin/X :0 -br -audit 0 -auth /var/lib/gdm/:0.Xauth -nolisten tcp vt7

1
By: mulad
2009-02-18 23:37:35

These Might Interest You

  • Show disk space info, grepping out the uninteresting ones beginning with ^none while we're at it. The main point of this submission is the way it maintains the header row with the command grouping, by removing it from the pipeline before it gets fed into the sort command. (I'm surprised sort doesn't have an option to skip a header row, actually..) It took me a while to work out how to do this, I thought of it as I was drifting off to sleep last night! Show Sample Output


    0
    df -h | grep -v ^none | ( read header ; echo "$header" ; sort -rn -k 5)
    purpleturtle · 2011-03-16 14:25:45 1
  • Also removes translator comments. You can remove the header by omitting --keep-header, but if your msgids contain non-ASCII characters you will need the header to specify a suitable charset.


    0
    msgfilter --keep-header --input input.po awk '{}' | sed '/^#$/d; /^#[^\:\~,\.]/d' >empty.po
    seanf · 2013-02-08 08:05:32 0
  • Put this code in a bash script. The script expects the PDF file as its only parameter. It will add a header to the PDF containing the page numbers and output it to a file with the suffix "-header.pdf" Requires enscript, ps2pdf and pdftk.


    1
    enscript -L1 -b'||Page $% of $=' -o- < <(for i in $(seq "$(pdftk "$1" dump_data | grep "Num" | cut -d":" -f2)"); do echo; done) | ps2pdf - | pdftk "$1" multistamp - output "${1%.pdf}-header.pdf"
    captaincomic · 2012-01-27 12:26:33 2
  • will display typedefs, structs, unions and functions declared in 'stdio.h'(checkout _IO_FILE structure). It will be helpful if we want to know what a particular header file will offer to us. Command 'cpp' is GNU's C Preprocessor.


    4
    cpp /usr/include/stdio.h | grep -v '^#' | grep -v '^$' | less
    mohan43u · 2009-05-22 22:40:25 2

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: