Commands by d34dh0r53 (5)

  • Prints the top 10 memory consuming processes (with children and instances aggregated) sorted by total RSS and calculates the percentage of total RAM each uses. Please note that since RSS can include shared libraries it is possible for the percentages to add up to more that the total amount of RAM, but this still gives you a pretty good idea. Also note that this does not work with the mawk version of awk, but it works fine with GNU Awk which is on most Linux systems. It also does not work on OS X. Show Sample Output

    TR=`free|grep Mem:|awk '{print $2}'`;ps axo rss,comm,pid|awk -v tr=$TR '{proc_list[$2]+=$1;} END {for (proc in proc_list) {proc_pct=(proc_list[proc]/tr)*100; printf("%d\t%-16s\t%0.2f%\n",proc_list[proc],proc,proc_pct);}}'|sort -n |tail -n 10
    d34dh0r53 · 2010-03-27 01:34:50 4
  • This command loops over all of the processes in a system and creates an associative array in awk with the process name as the key and the sum of the RSS as the value. The associative array has the effect of summing a parent process and all of it's children. It then prints the top ten processes sorted by size. Show Sample Output

    ps axo rss,comm,pid | awk '{ proc_list[$2]++; proc_list[$2 "," 1] += $1; } END { for (proc in proc_list) { printf("%d\t%s\n", proc_list[proc "," 1],proc); }}' | sort -n | tail -n 10
    d34dh0r53 · 2010-03-03 16:41:05 2
  • I prefer the ip command to ifconfig as ifconfig is supposedly going to be deprecated. Certain IP address aliases can only be seen with the ip command (such as the ones applied by RHCS).

    ip link show
    d34dh0r53 · 2010-03-01 20:10:27 0
  • Change the name of the process and what is echoed to suit your needs. The brackets around the h in the grep statement cause grep to skip over "grep httpd", it is the equivalent of grep -v grep although more elegant. Show Sample Output

    TOTAL_RAM=`free | head -n 2 | tail -n 1 | awk '{ print $2 }'`; PROC_RSS=`ps axo rss,comm | grep [h]ttpd | awk '{ TOTAL += $1 } END { print TOTAL }'`; PROC_PCT=`echo "scale=4; ( $PROC_RSS/$TOTAL_RAM ) * 100" | bc`; echo "RAM Used by HTTP: $PROC_PCT%"
    d34dh0r53 · 2010-02-26 20:29:45 3
  • Provides numerically sorted human readable du output. I so wish there was just a du flag for this. Show Sample Output

    du -x --max-depth=1 | sort -n | awk '{ print $2 }' | xargs du -hx --max-depth=0
    d34dh0r53 · 2010-02-18 19:46:47 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

Retry the previous command until it exits successfully

List the size (in human readable form) of all sub folders from the current location
Sorted in human readable format.

sync two folders except hidden files

Convert ascii string to hex

Locking and unlocking files and mailboxes
Programs for locking and unlocking files and mailboxes.This package includes several programs to safely lock and unlock files and mailboxes from the command line. These include: lockfile-create lockfile-remove lockfile-touchlock mail-lock mail-unlock mail-touchlock These programs use liblockfile to perform the file locking and unlocking, so they are guaranteed compatible with Debian's file locking policies.

When feeling down, this command helps
$ sudo apt-get install sl $ man sl

encrypt whole line with ROT13 in vim

Install pip with Proxy
Installs pip packages defining a proxy

Remote backups with tar over ssh
Execute it from the source host, where the source files you wish backup resides. With the minus '-' the tar command deliver the compressed output to the standar output and, trough over the ssh session to the remote host. On the other hand the backup host will be receive the stream and read it from the standar input sending it to the /path/to/backup/backupfile.tar.bz2

Rename all files which contain the sub-string 'foo', replacing it with 'bar'
That is an alternative to command 8368. Command 8368 is EXTREMELY NOT clever. 1) Will break also for files with spaces AND new lines in them AND for an empty expansion of the glob '*' 2) For making such a simple task it uses two pipes, thus forking. 3) xargs(1) is dangerous (broken) when processing filenames that are not NUL-terminated. 4) ls shows you a representation of files. They are NOT file names (for simple names, they mostly happen to be equivalent). Do NOT try to parse it. Why? see this : Recursive version: $ find . -depth -name "*foo*" -exec bash -c 'for f; do base=${f##*/}; mv -- "$f" "${f%/*}/${base//foo/bar}"; done' _ {} +

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: