06
Jul
09

Bash aliases: check memory usage, package management, and more!

Check the memory usage of your favourite application in style. Grep the output of ps!

Code:
function ram() { ps auxf | grep $1 | grep -v grep | awk '{sum=sum+$6}; END {print sum+1023/1024}' ; }

Append the time and date to the start of your files.

Code:
function datestamp()
	{
	for x in $@; do
		if [ -e $x ]; then
			mv $x $(date +'%F')-$x
		else
			echo "$x? File doesn't exist, fool."
		fi
	done
	}

Install, remove, autoremove and purge. Now renamed Loadry, unloadry, laundry and nuke, respectively.

Code:
function loadry () {
        if [ $(whoami) != "root" ] ; then
           sudo apt-get install $@
        else
           apt-get install $@
        fi
      }

function unloadry() {
	if [ $(whoami) != "root" ] ; then
	   sudo apt-get remove $@
	else
	   apt-get remove $@
	fi
      }

function laundry() {
	if [ $(whoami) != "root" ] ; then
	   sudo apt-get autoremove $@
	else
	   apt-get autoremove $@
	fi
      }

function nuke() {
	if [ $(whoami) != "root" ] ; then
	  sudo apt-get autoremove --purge $@
	else
	  apt-get autoremove --purge $@
	fi
      }

For anybody who followed the Futurama tutorial, here’s a little something extra, just for you.

Code:
function woots() { #!/bin/bash
  cows=(/usr/share/cowsay/cows/*.cow)
  num=${#cows[@]}
  ((num=RANDOM%num))
  randcow=`echo ${cows[$num]}`
  if [[ $randcow = "/usr/share/cowsay/cows/leela.cow" ]] || [[ $randcow = "/usr/share/cowsay/cows/fry.cow" ]] || [[ $randcow = "/usr/share/cowsay/cows/bender.cow" ]];
    then futurama;
  else
    phrase=`fortune -a`
    cowsay -f $randcow $phrase;
  fi;
}

Ah shucks, maybe someone will find this nonsense useful some day.

Advertisements

0 Responses to “Bash aliases: check memory usage, package management, and more!”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


July 2009
M T W T F S S
    Aug »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Stuff goes here

Hijack this blog

You want to use something from this blag? What the hell is wrong with you? Do you want to fail at life? If you reuse the crap I post here, people will say, "Wow, I never knew anybody could be so ignorant!" Then they will go and find a weapon to beat you with. That's right. There's your god-damned copyright notice. You really care about that shit? Fine. Take it, copy it, pretend it's your own work. Do whatever the hell you want with it, I don't care.

Blog Stats

  • 13,560 people hate me.

%d bloggers like this: