More linux snippets
Need to remove all those ^M characters from a DOS file? Try
tr -d \\r < dosfile > newfile
Need to find which process is taking up a certain port?
sudo fuser -n tcp 8080
get details on a certain process?
ps -eaf | grep 22450
Show which processes are using which sockets
sudo netstat -nlp
Split a file on x lines
split -l 409000 catalina.out
this will generate files like xaa, xab, xac, xad, ....
Join these split files back
cat x* > joined.log
Analyse a logfile and retrieve only the ERROR lines and their Cause:
egrep 'Cause|ERROR' catalina.out > catalina_errors.out
or using grep (don't forget to escape the pipe):
grep "Cause\|ERROR" catalina.out
Shopt:
shopt -s nocaseglob
Use wget to follow hyperlinks from a text file, log the server response and exclude media files
wget -b -H -r --level=1 --no-parent -e robots=off -o wget.log -O output.log -i input.txt --server-response --save-headers -R *.gif,*.css,*.xml,*.swf,*.png,*.jpg,*.xml,*.js,\' --follow-tags=a
or simply
wget -b -o wget.log -O output.log -i input.txt --server-response
Then grep the logfile to detect all links and if they failed:
cat wget.log | grep '\-\-\|HTTP\|failed'
Open winmail.dat files on Ubuntu:
sudo apt-get install tnef
tnef winmail.dat
Fix corrupted zip files in Linux
zip –F "filename.zip"
And if that doesn't work: make zip work harder:
zip –FF "filename.zip"
And finally a simple regex to match 4 or more consecutive letters or numbers
([a-z-0-9])\1{3,}
To end on a lighter note: a nice website containing funny source code comments:
http://cobaia.net/2010/09/top-funny-source-code-comments/