Bash Tricks Cheatsheet - Be a Bash Wizard! 04-17-2012, 10:28 PM
#1
Hi all 
I don't know if anybody post this before or not (i didn't find it in the list atleast :nono: ) so i'd make it for you guys whoever wants to use these.
These are some tricks to use BASH and other *nix utilities in the best way possible to ease up your terminal jobs
So here it is:
Create iso image of cd/dvd
geoip information
convert html links into plain text with link anchor
copy hybrid iso images to USB key for booting from it, progress bar and remaining time are displayed while copying
Remove a range of lines from a file
Remove a range of lines from a file
Transfer a file to multiple hosts over ssh
Completely blank a disk
OR
Replace duplicate files by hardlinks
tell if a port is in use
regex for turning a URL into a real hyperlink (i.e. for posting somewhere that accepts basic html)
Daemonize nc - Transmit a file like a http server
vim read stdin
Copy all files, including hidden files, recursively without traversing backward
list with full path
Show what PID is listening on port 80 on Linux
Fix MP3 tags encoding (to UTF-8). Batch fixes all MP3s in one directory.
Show which user has the most accumulated login time
convert ascii string to hex
So here was the list of tricks, some i discovered, most i found on various websites looking for shortcuts to "get a bash life"
hope they will be useful to someone! Sorry but i have not mentioned tit-bits above (like "replace this port # with your own" and so and so) so this list might not be noob friendly. but i guess you can figure them all out.
It's 3:00 *AM* here right now. Imagine a half-sleepy dead guy tapping madly at his keyboard :headbash:
get you more linux/programming/hacking tips and tricks soon!
cheers!

I don't know if anybody post this before or not (i didn't find it in the list atleast :nono: ) so i'd make it for you guys whoever wants to use these.
These are some tricks to use BASH and other *nix utilities in the best way possible to ease up your terminal jobs

So here it is:
Create iso image of cd/dvd
Code:
dd if=/dev/cdrom of=~/cdimage.isogeoip information
Code:
curl -s ifconfig.me|tee >(xargs geoiplookup)convert html links into plain text with link anchor
Code:
sed 's!<[Aa] *href*=*"\([^"]*\)"*>\([^<>]*\)</[Aa]>!\1,\2!g' links.htmlcopy hybrid iso images to USB key for booting from it, progress bar and remaining time are displayed while copying
Code:
pv -petrs $(stat -c %s file.iso) file.iso | dd bs=1M oflag=sync of=/dev/sdXRemove a range of lines from a file
Code:
perl -i -ne 'print if $. == 3..5' <filename>Remove a range of lines from a file
Code:
vi +{<end>..<start>}d +wq <filename>Transfer a file to multiple hosts over ssh
Code:
pscp -h hosts.txt -l username /etc/hosts /tmp/hostsCompletely blank a disk
Code:
dd if=/dev/urandom of=/dev/somediskCode:
shred --iterations=N /dev/sdaXReplace duplicate files by hardlinks
Code:
fdupes -r -1 Neu | while read line; do j="0"; buf=""; for file in ${line[*]}; do if [ "$j" == "0" ]; then j="1"; buf=$file; else ln -f $buf $file; fi; done; donetell if a port is in use
Code:
netstat -a --numeric-ports | grep 8321regex for turning a URL into a real hyperlink (i.e. for posting somewhere that accepts basic html)
Code:
sed "s/\([a-zA-Z]*\:\/\/[^ ]*\)\(.*\)/\<a href=\"\1\"\>\1\<\/a\>\2/"Daemonize nc - Transmit a file like a http server
Code:
while ( nc -l 80 < /file.htm > : ) ; do : ; done &vim read stdin
Code:
ls | vim +'set bt=nowrite' -Copy all files, including hidden files, recursively without traversing backward
Code:
cp -r * .??* /destlist with full path
Code:
ls -a | sed "s#^#${PWD}/#"Show what PID is listening on port 80 on Linux
Code:
fuser -v 80/tcpFix MP3 tags encoding (to UTF-8). Batch fixes all MP3s in one directory.
Code:
find . -iname "*.mp3" -execdir mid3iconv -e <encoding> {} \;Show which user has the most accumulated login time
Code:
ac -p | sort -nk 2 | awk '/total/{print x};{x=$1}'convert ascii string to hex
Code:
python -c 'print "hello".encode("hex")'
So here was the list of tricks, some i discovered, most i found on various websites looking for shortcuts to "get a bash life"
hope they will be useful to someone! Sorry but i have not mentioned tit-bits above (like "replace this port # with your own" and so and so) so this list might not be noob friendly. but i guess you can figure them all out.It's 3:00 *AM* here right now. Imagine a half-sleepy dead guy tapping madly at his keyboard :headbash:
get you more linux/programming/hacking tips and tricks soon!

cheers!
~ # INDIAN ROGUE MERCENARY HACKER # ~


![[+]](https://sinister.li/images/modern/collapse_collapsed.png)