Login Register






Bash Tricks Cheatsheet - Be a Bash Wizard! filter_list
Author
Message
Bash Tricks Cheatsheet - Be a Bash Wizard! #1
Hi all Smile

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 Biggrin
So here it is:

Create iso image of cd/dvd
Code:
dd if=/dev/cdrom of=~/cdimage.iso

geoip 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.html

copy 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/sdX

Remove 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/hosts

Completely blank a disk
Code:
dd if=/dev/urandom of=/dev/somedisk
OR
Code:
shred --iterations=N /dev/sdaX

Replace 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; done

tell if a port is in use
Code:
netstat -a --numeric-ports | grep 8321

regex 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 * .??* /dest

list with full path
Code:
ls -a | sed "s#^#${PWD}/#"

Show what PID is listening on port 80 on Linux
Code:
fuser -v 80/tcp

Fix 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")'

Cool So here was the list of tricks, some i discovered, most i found on various websites looking for shortcuts to "get a bash life" Biggrin 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! Wink

cheers! Biggrin
~ # INDIAN ROGUE MERCENARY HACKER # ~

Reply