UNIX notes

grep -v “^$” filename > newfilename

lsof -P -i -n

tcpdump -i eth0 host 192.168.1.1

netstat -t -u -c

hdparm -t /dev/sda
Test hard disk reading speed

echo “foo” > /dev/tcp/192.168.1.2/25
send echo to socket network

awk ‘length>72’ file
list of lines that are longer than 72 characters

sudo mknod /dev/ttyS4 c 4 68
Add another tty device using mknod command

find ~ -name ‘*.mp4’ | xargs mplayer
play all mp4 files on home directory

a2ps –line-number=5 message.rb

stop process using bash ^Z
[2]+ Stopped
you can view these processes with $jobs
then you can refer them to %2
e.g. $kill %2
$bg %2
$fg %2

find . -name '*.txt' | xargs perl -pi -e 's/old_str/new_str/g'

~/jruby/bin/jruby -J-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=4000 -J-Xdebug dioneas.rb ../sample/ruby/philosophers.rb

find ./ -type d -name .svn -exec rm -fr {} +

rm !(b)…..removes all file but b

#disable ipv6
net.ipv6.conf.all.disable_ipv6=1
#sysctl -w
echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6

-Djava.net.preferIPv4Stack=true

Ghostscript

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -dNumRenderingThreads=3 -sOutputFile=output.pdf input.pdf
-dNOGC — NO garbage collection
-c “30000000 setvmthreshold” –30MB of RAM
-dPDFSETTINGS=/screen (screen-view-only quality, 72 dpi images)
-dPDFSETTINGS=/ebook (low quality, 150 dpi images)
-dPDFSETTINGS=/printer (high quality, 300 dpi images)
-dPDFSETTINGS=/prepress (high quality, color preserving, 300 dpi imgs)
-dPDFSETTINGS=/default (almost identical to /screen)

pdftk sales_report.pdf output SalesReport.pdf user_pw PROMPT

echo “test” | ssh user@192.168.0.138 ‘cat > file’

CREATE DATABASE newdb WITH TEMPLATE originaldb OWNER dbuser;

patch -p0 -i ~/fix.diff

sed -n 5647,6239p app.log > relevant.log


python -m SimpleHTTPServer 8000



(server)$ cat file.zip | nc -l 8888
(client)$ nc <server> 8888 > file.zip

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s