Skip to content

Short Scripts and Aliases

For taking quick notes on the command line

alias note='echo `date`: $1 >> /home/ifx/Documents/notes'
alias notes='tail /home/ifx/Documents/notes'

Set "/home/ifx/Documents/notes" to the path to the notes file on your system, of course.
This just uses tail's default value, but you can set the number of lines printed by notes easily as you would with tail:

notes -n 2

shows the last two notes taken.

Show and hide desktop icons

alias show_desktop='gconftool-2 --set --type bool /apps/nautilus/preferences/show_desktop true'
alias hide_desktop='gconftool-2 --set --type bool /apps/nautilus/preferences/show_desktop false'

(with Gnome)

Convert between data units (SI and IEC)

?Download size.py
#!/usr/bin/python
from __future__ import division
import sys
 
def convert(a, u):
    n = ""
    v = ""
    for char in a:
        if char.isdigit() or char == ".":
            n += char
        else:
            v += char
    n = float(n)
    suf = {"B" : 8, "b" : 1, "bit" : 1}
    iec = {"K" : 10, "M" : 20, "G" : 30, "T" : 40, "P" : 50, "E" : 60, "Z" : 70, "Y" : 80}
    si = {"k" : 3, "K" : 3, "M" : 6, "G" : 9, "T" : 12, "P" : 15, "E" : 18, "Z" : 21, "Y" : 24}
 
    if len(v) == 1 or v == "bit" or v == "bits":
        bits = n * suf[v[0]]
    elif v[1] == "i":
        bits = n * 2**iec[v[0]] * suf[v[2]]
    else:
        bits = n * 10**si[v[0]] * suf[v[1]]
    if len(u) == 1 or v == "bit" or v == "bits":
        out = bits
        if u[0] == "B":
            out /= 8
    elif u[1] == "i":
        out = bits
        if u[2] == "B":
            out /= 8
        out /= 2**iec[u[0]]
    else:
        out = bits
        if u[1] == "B":
            out /= 8
        out /= 10**si[u[0]]
    return out
 
print convert(sys.argv[1], sys.argv[2])

Example: ./size.py 8kbits B yields 1000.0.