Friday, December 10, 2010
Friday, November 19, 2010
Random words generator in bash (random line reader)
n=$(cat /usr/share/dict/words | wc -l)
sed $(( ($RANDOM * 32768 + $RANDOM) % n ))"q;d" /usr/share/dict/words
sed $(( ($RANDOM * 32768 + $RANDOM) % n ))"q;d" /usr/share/dict/words
Labels:
admin,
bash,
command line,
random,
reader,
words,
words generator
How to replace some text in next line that forwards after matched to current line
#!/bin/sh
sed '/ONE/ {
N
s/TWO//
}' < text.txt > text.txt.tmp
sed '/ONE/ {
N
s/TWO//
}' < text.txt > text.txt.tmp
Wednesday, November 10, 2010
SQL for delete duplicates
delete from table where id in (select (select id from table where col82 = x.col82 order by id asc limit 1) from (select count(id) cnt, col82 from table group by col82 order by cnt desc) x where x.cnt > 1);
Friday, November 5, 2010
Mini one page web server by using netcat (nc)
It will be helpful for debugging requests. You need bash and nc.
For some reasons debian and ubuntu have different net cat's version with different syntax:
- debian:
while echo -e "HTTP/1.0 200 OK\nContent-Type: text/html\n\n" | netcat -v -v -q 1 -lp 60000; do echo ""; done
- ubuntu:
while echo -e "HTTP/1.0 200 OK\nContent-Type: text/html\n\n" | netcat -lv 60000; do echo ""; done
To test it use command: netcat localhost 60000
For some reasons debian and ubuntu have different net cat's version with different syntax:
- debian:
while echo -e "HTTP/1.0 200 OK\nContent-Type: text/html\n\n" | netcat -v -v -q 1 -lp 60000; do echo ""; done
- ubuntu:
while echo -e "HTTP/1.0 200 OK\nContent-Type: text/html\n\n" | netcat -lv 60000; do echo ""; done
To test it use command: netcat localhost 60000
Thursday, October 28, 2010
Friday, October 22, 2010
Kill only tomcat, java survive
ps auxww | grep tomcat | grep -v grep | awk '{ print $2 }' | xargs kill -9
Monday, September 27, 2010
Tuesday, August 31, 2010
How to normalize permissions 644 for files 755 for directories
for i in `find . -type d`; do chmod 755 $i; done
for i in `find . -type f`; do chmod 644 $i; done
Thursday, August 19, 2010
How to url encode string/file in bash cmd
echo "sdf sd fs / df"| perl -MURI::Escape -lne 'print uri_escape($_)'
Friday, July 16, 2010
How to backup directory to remote server with rsync
rsync -r -v -e ssh /www/backup jerry@openbsd.nixcraft.in:~
Thursday, June 17, 2010
How to send email from bash with attachment using standard unix utils
mpack -s "Subject" -c application/octet-stream /home/user/file.zip friends@email.com
Wednesday, June 16, 2010
How to extract some file from rar archive under bash
rar x archive.rar archives/sql/file.ext /tmp
rar vb archive.rar | grep file
Tuesday, June 8, 2010
Monday, March 22, 2010
Monday, February 15, 2010
How to delete all folders with specific size
du -s * | grep 12776 | awk '{split($0,a," "); print a[2]}' > /tmp/a
while read line; do rm -rf $line; done < /tmp/a
while read line; do rm -rf $line; done < /tmp/a
Subscribe to:
Comments (Atom)