My Commands

__NOINDEX__

= Networking =

Quick Traceroute traceroute -n -w 1 -m 10 4.2.2.2

Save Packet Captures tcpdump -s 0 -i eth0 host 10.1.1.1 -v -w /tmp/packet_capture.cap

Netstat list Applications along with open port numbers netstat -anp 8080 netstat -an | grep 8080

Show active connections/Applications only sudo netstat -tulpn

netstat -lnt

= List Files =

Sort List by Time ls -lhtra

Sort List by Size ls -lhSra

Do not sort; list entries in directory order ls -U

= Bash =

Execute cmd in other dir & return back to original dir (cd /etc && ls -a)

Copy/Move all files from sub directories into current dir cp ./*/*. mv ./*/*.

Loop Commands for i in `find. -type f`; do echo $i; cat $i; done | grep terminate while true; do this; do that; sleep 2; done for i in `find $(pwd) -type f -name '*.gz'`; do echo $i; j=$(echo $i | cut -d '.' -f1); echo $j; mkdir $j; tar xvzf $i -C $j; done     # create subdir/extract to folder

Redirect Standard error to null: find / -name 'geeqierc.xml' 2>/dev/null

Flush Logs without delete for i in *; do >$i; done

= Extracting Archives =

Extract "*.gz" file gunzip FILE_NAME.gz

Extract "*.tar.gz" file tar zxf FILE_NAME.tar.gz

Extract "*.tar.bz2" file tar jxf FILE_NAME.tar.bz2

= Generate 100 HTTP requests = sudo apt-get install parallel seq 100 | parallel --no-notice -j0 --joblog log curl -s http://10.107.88.91/welcome.png/{} ">" {}.txt cut -f 4 log seq 100 | parallel --no-notice -j0 --joblog log curl http://10.107.88.91/welcome.png/{} ">" {}.txt

= Finding Old Logs = find /tmp/report_ftw -type f -mtime +30 find /tmp/report_ftw -type f -mtime +30 -name "messages.*" -exec rm -f {} \;
 * Find and Delete more than 30 days old files:

find /var/log -type f -mtime +30 -name "*.gz" -exec ls {} \; find /var/log -type f -mtime +30 -name "*.gz" -exec rm -f {} \;
 * List and Delete gz files older than 30 days:

= Searching Multiple text files = for i in log*; do echo $i ; cat $i | egrep -vi "error|not|warning|false" ; done