Unix Cheat Sheet

Contents

Useful commands

Recursively remove CVS $header$ headers

for file in `find . -type f | xargs`
do
    sed '/# $Header/d' $file > $file.new
    mv $file.new $file
done

The above can be achieved more succinctly using perl. For example simple string replacement in place.

> perl -pi -w -e 's/jdbc_informix_driver/jdbc_informix_url/g;' $( find . -name "*.yml" )

This would recursively find all yaml files and run sed expression doing in-place edit.

-e execute the following line of code.
-i edit in-place
-w write warnings
-p loop

IP Whitelist apache virtual hosts

The below code will only allow localhost access to the yum repos, example taken from blog.lysender.com

<Directory "/var/www/html/yum">
    Options Indexes FollowSymLinks
    AllowOverride All
    Order deny,allow
    Allow from 127.0.0.1
    Allow from xxx.xxx.xxx.xxx
    Allow from xxx.xxx.xxx.xxx
    Deny from all
</Directory>

Convert file from ISO88591 -> UTF-8

> iconv -f ISO-8859-15 -t UTF-8 iso88591.dat > utf8.dat

Hexdump a single line from a file

> sed '1944q;d' utf8.dat |hexdump -C

00000000  31 31 30 30 30 32 33 37  30 7c 7c 7c 7c 4f 6c 65  |110002370||||Ole|
00000010  20 47 75 6e 6e 61 72 7c  53 6f 6c 73 6b 6a c3 a6  | Gunnar|Solskj..|
00000020  72 7c 7c 7c 7c 0a                                 |r||||.|
00000026
comments powered by Disqus