Follow me: @D_mitar

Most read posts recently



Sep 23rd 2010 × Bash scripting: find recently modified files on a linux/*nix server

This has turned out to be a somewhat tricky task – to find all updated files since nn-number of days within the current path / directory tree.

The first bit was, use the find command like so:

find . -mtime -3 -printf "%Tx\t%p\n"

This gives you the modified date and name / relative path of all changed files within the last 3 days However, setting this as a bash alias means you cannot pass an argument for the number of days to go back. That’s when using bash functions can come to the rescue (stick this in your ~/.bashrc):

function nf() { find . -mtime -$1 -printf "%Tx\t\t\t%p\n" ;}

to use, simply do:

# nf 4
09/23/2010                      ./migrate-newproduct.sh
09/22/2010                      ./tips.sql
# nf 20 | grep sql
...

You may need to do . ~/.bashrc first to make the function stick. Simple, really. For more formatting on find, just google the printf API.

Another really useful bash feature I have recently added to my shell is forward and backward lookup history via .inputrc:

"\C-f": history-search-backward
"\C-g": history-search-forward

This works by typing the first few letters of a recent command you may have entered on the console and pressing CTRL-F for a forward lookup or CTRL-G to go back to the previous entry – in a way, tab completion. Fully supported by MySQL as well, which is very handy indeed!

no

Oct 19th 2008 × YSlow and mod_rewrite: helping in site speed profiling and optimisation

I have been looking around a fair bit recently in a bid to improve performance on a number of sites… And naturally came upon YSlow for FireBug. This is a plugin that does website component profiling based on analysing the performance of all elements loaded into DOM. It examines headers, compression, size, response time, content types and can produce an accurate depiction of your worst performing scripts, stylesheets or images.

It also has a great advisory feature that uses YUI’s best practices in website optimisation (such as, gzipping components, using CDNs, marginalising background images, minimizing requests, to name but a few). It measures and ranks your site and makes you want to tweak it and improve…

I had a long play with various ways of improving but eventually came get to the best results (as speed and size gains) via some mod_rewrite .htaccess trickey:

## enable gzip page compression!
php_flag zlib.output_compression On
php_value zlib.output_compression_level 5

# compress all text & html:
AddOutputFilterByType DEFLATE text/html text/plain text/xml

<Files *.js>
SetOutputFilter DEFLATE
</Files>

<Files *.css>
SetOutputFilter DEFLATE
</Files>

# set clientside cache per element type
# 1 YEAR
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
</FilesMatch>
# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
# 2 DAYS
<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=172800, proxy-revalidate"
</FilesMatch>

This is a combination between cache controls and compression that you can tweak and deploy as needed. If you have relatively static .html or .php files, you can also try adding |html|php or whatever other extension you may see fit. Have fun.

no