24May/110
dump packets with tcpdump
I always forget the parameters for this and have to look them up in the man page, so enough of that:
tcpdump -nnXSs 0 host hostname (or IP)
- "-nn" makes it not lookup hostnames in DNS and service names (in /etc/services) for respectively faster and cleaner output.
- "-X" makes it print each packet in hex and ascii; that's really the useful bit for tracking headers and such
- "-S" print absolute rather than relative TCP sequence numbers - If I remember right this is so you can compare tcpdump outputs from multiple users doing this at once
- "-s 0" by default tcpdump will only capture the beginning of each packet, using 0 here will make it capture the full packets.
19Apr/110
The Alteration Operator
Using egrep, the following will match all lines from the 9th, 10th, 11th, and 12th hours of Sunday April 10th in the log file eventdump.txt:
$ egrep Sun\ Apr\ 10\ \('09|10|11|12'\)\: eventdump.txt
(I always forget to escape the parenthesis.)
22Mar/110
Match patterns using perl on the command line
Since I can never remember this: The following one-liner will print every line in file.txt that matches your pattern "match".
perl -l -n -e 'print $1 if /(.*match.*)/' file.txt
22Feb/100
Change uppercase filenames to lowercase
I needed to rename a handful of image files from my iPhone from all uppercase letters to lowercase. I did this in a bash shell in Fedora linux. Here's how I did it:
[dacaprice@fedora10]$ for i in `ls *JPG` do mv $i `echo $i | tr '[:upper:]' '[:lower:]'` done