Commands by lostnhell (1)

  • explanation: grep -- displays process ids -v -- negates the matching, displays all but what is specified in the other options -u -- specifies the user to display, or in this case negate The process loops through all PIDs that are found by pgrep, then orders a forced kill to the processes in numerical order, effectively killing the parent processes first including the shells in use which will force the users to logout. Tested on Slackware Linux 12.2 and Slackware-current

    for i in $(pgrep -v -u root);do kill -9 $i;done
    lostnhell · 2009-03-24 02:54:52 2

What's this? 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

Check These Out

grep processes list avoiding the grep itself
Trick to avoid the form: grep process | grep - v grep

create new branch from stashed changes
from Useful for when stash cannot be applied to current branch

List status of your git repos and let us know if there is any new files to commit.

A function to output a man page as a pdf file
Tested on Fedora 12. This function will take a man page and convert it to pdf, saving the output to the current working directory. In Gnome, you can then view the output with "gnome-open file.pdf", or your favorite pdf viewer.

Fast tape rewind
Traditionally we rewind a tape using this syntaxis: $ mt -f /dev/rmt/0cbn rewind Redirecting the dispositive to nothing as shown above is faster. Less typing is always better.

Print every Nth line
Sometimes commands give you too much feedback. Perhaps 1/100th might be enough. If so, every() is for you. $ my_verbose_command | every 100 will print every 100th line of output. Specifically, it will print lines 100, 200, 300, etc If you use a negative argument it will print the *first* of a block, $ my_verbose_command | every -100 It will print lines 1, 101, 201, 301, etc The function wraps up this useful sed snippet: $ ... | sed -n '0~100p' don't print anything by default $ sed -n starting at line 0, then every hundred lines ( ~100 ) print. $ '0~100p' There's also some bash magic to test if the number is negative: we want character 0, length 1, of variable N. $ ${N:0:1} If it *is* negative, strip off the first character ${N:1} is character 1 onwards (second actual character).

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Get all upgradable deb packages in a single line
Works for debian and ubuntu based distros.

Remove duplicate rows of an un-sorted file based on a single column
$F[0] filters using first word. $F[1] - 2nd, and so on.

Push your present working directory to a stack that you can pop later
If are a Bash user and you are in a directory and need to go else where for a while but don't want to lose where you were, use pushd instead of cd. cd /home/complicated/path/.I/dont/want/to/forget pushd /tmp cd thing/in/tmp popd (returns you to /home/complicated/path/.I/dont/want/to/forget)

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.


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: