pretty

Thursday, December 26, 2013

Compare directory trees

bash version

diff <(cd dir1 && find | sort) <(cd dir2 && find | sort)

Python version soon . . .

Monday, November 18, 2013

Disable line wrap in bash

Disables
printf '\033[?7l'
Enables
printf '\033[?7h'

Brief pcap view with tshark

tshark -T fields -eip.src -e tcp.srcport -eip.dst -e tcp.dstport -e text -r http.cap | sed -e 's/Source GeoIP: Unknown,Destination GeoIP: //g'

Thursday, August 29, 2013

Traverse a directory in python

#!/usr/bin/env python
# -*- coding: utf-8 -*- 
import os

for root, dirs, files in os.walk(rootpath):
	for filename in files:
		path = os.path.join(root, filename)
		print path

With file filtering

#!/usr/bin/env python
# -*- coding: utf-8 -*- 
import os
import fnmatch

pattern = "*.conf"
rootpath = "/etc"
for root, dirs, files in os.walk(rootpath):
	for filename in fnmatch.filter(files, pattern):
		path = os.path.join(root, filename)
		print path
Python 2.7 documentation on os

Thursday, May 30, 2013

Concatenate files in python


cat folder/* > outfile

import fileinput
with open(outfilename, 'w') as fout:
for line in fileinput.input(filenames):
fout.write(line)

Thursday, April 25, 2013

Show specific line in large file

Show only line 20 

sed -n '20p' file_name

Show 10 through 20 

sed -n '10,20p' file_name

Show 10 and 20 

sed -n '10p;20p' file_name