Commands by toxick (2)

  • 1
    netstat -tn | awk '($4 ~ /:22\s*/) && ($6 ~ /^EST/) {print substr($5, 0, index($5,":"))}'
    toxick · 2012-10-03 04:47:54 0
  • Using the output of 'ps' to determine CPU usage is misleading, as the CPU column in 'ps' shows CPU usage per process over the entire lifetime of the process. In order to get *current* CPU usage (without scraping a top screen) you need to pull some numbers from /proc/stat. Here, we take two readings, once second apart, determine how much IDLE time was spent across all CPUs, divide by the number of CPUs, and then subtract from 100 to get non-idle time. Show Sample Output

    NUMCPUS=`grep ^proc /proc/cpuinfo | wc -l`; FIRST=`cat /proc/stat | awk '/^cpu / {print $5}'`; sleep 1; SECOND=`cat /proc/stat | awk '/^cpu / {print $5}'`; USED=`echo 2 k 100 $SECOND $FIRST - $NUMCPUS / - p | dc`; echo ${USED}% CPU Usage
    toxick · 2012-10-02 03:57:51 1

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

DVD to YouTube ready watermarked MPEG-4 AVI file using mencoder (step 2)
Reencodes to MPEG-4 DivX output video file from step 1. Audio stream is simply copied. Resizes to 320x240 and deinterlaces as needed. A heading subtitle file is applied as watermark. This heading subtitle file can be a URL.

get the top 10 longest filenames

Create/open/use encrypted directory
Create/open/use an encrypted directory encfs needs to be installed During creation easiest to use default values The encrypted files will be in ~/.crypt and you will work as usual in ~/crypt To close the encrypted directory run: fusermount -u ~/crypt When you switch off the computer the encrypted directory will be automatically closed This example uses /home/user/crypt as encrypted directory I use ubuntu linux 8.04 and I am also the creator of

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"

show the date every rpm was installed
the newest rpms are at the top; individual packages can also be queried this way: rpm --last -q package

Remove all zero size files from current directory (not recursive)

Throttling Bandwidth On A Mac
sudo ipfw pipe 1 config bw 50KByte/s Set the bandwidth (bw) limit to any number you want. For example you could have a 15kb pipe for X application and then a 100kb pipe for another application and attach things to those pipes. If a port isn’t attached to a pipe, it runs at full speed. Change the number (in this case 1) to a different number for a different pipe. The next step is to attach your port. sudo ipfw add 1 pipe 1 src-port 80 In this case anything on port 80 (http) will be set to a limit of 50Kbyte/s. If you want to attach a second port to this pipe, repeat the command but change the port number at the end. src :

Empty the linux buffer cache

Set laptop display brightness
Run as root. Path may vary depending on laptop model and video card (this was tested on an Acer laptop with ATI HD3200 video). $ cat /proc/acpi/video/VGA/LCD/brightness to discover the possible values for your display.

Create a random password encrypted with md5 with custom lenght
This was useful to generate random passwords to some webpage users, using the sample code, inside a bash script

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: