Bash
From Leaky
Find the location of a script, no matter how it's referenced when run
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" echo $DIR
Convert files/text to hex and back
I had a weird looking filename in a backup and found the following while trying to figure out what the character might be.
[user@host photos]$ ls | xxd -g1 0000000: ef 80 a3 33 2e 70 6e 67 0a ...3.png. [user@host photos]$ xxd -g1 -r 0000000: ef 80 a3 33 2e 70 6e 67 0a ...3.png. 3.png
xxd is part of vim-common on CentOS and it's better than od because -r will reverse the hex dump and convert it to a binary file!
replace file extensions without sed
for i in *.sh; do echo "${i%.sh}.bat"; done