More useful shell tricks for bash. These are very useful tricks for any Linux user.

This sed trick will filter out the unwanted characters and leave only the letters ‘A’.

homer@deusexmachina ~ $ echo "###AAA" | sed 's/###//gi'
AAA

This is how to re-bind the annoying CAPS-Lock key to Esc. This can give that key a new use.

xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape' &

Here is how to print the architecture of your Linux installation.

homer@deusexmachina ~ $ dpkg --print-architecture
amd64

How to test disk writing speed with the Linux command line.

homer@deusexmachina ~ $ dd if=/dev/zero of=/tmp/output.img bs=8k count=256k conv=fdatasync; rm -rf /tmp/output.img
262144+0 records in
262144+0 records out
2147483648 bytes (2.1 GB) copied, 19.4116 s, 111 MB/s

Generate a random password using /dev/urandom.

homer@deusexmachina ~ $ LANG=c < /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-16};echo;
wlQSgF8KpQBHiG5q

Show all tcp4 listening ports.

homer@deusexmachina ~ $ netstat -lnt4 | awk '{print $4}' | cut -f2 -d: | grep -o '[0-9]*'
443
445
139
51413
53
53
631

Get information about your user.

homer@deusexmachina ~ $ finger homer
Login: homer          			Name: John Cartwright
Directory: /home/homer              	Shell: /bin/bash
On since Mon Apr 21 14:14 (EST) on tty8 from :0
    7 hours 13 minutes idle
On since Mon Apr 21 18:48 (EST) on pts/0 from :0.0
No mail.
Plan:
DOS: n., A small annoying boot virus that causes random spontaneous system
     crashes, usually just before saving a massive project.  Easily cured by
     UNIX.  See also MS-DOS, IBM-DOS, DR-DOS.

No comments have been made. Use this form to start the conversation :)

Leave a Reply