Saturday, November 29, 2008

Funny UNIX tricks from Slashdot

There was a recent story on slashdot about useless (or useful) things one can do in UNIX. Being a command line junkie, I read through virtually every comment (all 2300+ of them) to learn some new tricks. Here are some of the better ones:

  • Bash History
    • history -c # clear history (good for preserving privacy/passwords, or check out the more precise -d option)
    • In vi command mode, type /query and hit Enter to search history, n to keep searching backwards, N to search forwards
  • vimdiff
    • vimdiff original_file patched_file
    • unified format: open original file, then :vertical diffpatch path/to/diff
  • Encryption
    • openssl aes-256-cbc -a -e -salt -in INPUT_FILENAME -out OUTPUT_FILENAME # encrypt
    • openssl aes-256-cbc -a -d -salt -in INPUT_FILENAME -out OUTPUT_FILENAME # decrypt
    • echo Oe lbh pna vzcyrzrag UK tbireazrag fgnaqneq rapelcgvba jvgu ge | tr a-z n-za-m # Rot 13 encrypt/decrypt
    Others:
    • sleep 8h; cat /dev/urandom > /dev/dsp # alarm clock
    • eject -T # close cd tray if open, open if closed (useful to find out which physical machine you are logged into)
    • sl # punish users who accidentally type 'sl' instead of 'ls'
    • eposd && say 'hello' # make the computer talk
    • :(){ :|:& };: # forkbomb (space required between { and :) (protect against this with ulimit -u)
    • for I in $(seq 1 100) ; do echo $I; sleep .25; done | dialog --gauge "PIZZA" 6 50 100 # Pizza timer via dialog

    No comments: