Home » Posts tagged "find"

Deleting files in Linux that are x-days old

Since I’m not running a PHP version provided by my distribution I’m responsible for cleaning up old session files myself. Aside from PHP another Perl webapp I run also doesn’t clean up its own session files. Luckily cleaning up these old files is something that’s very easy to do under Linux.

find /tmp/sess_* -mtime +2 -exec rm {} \;

In this example I’m only taking files that are at least 2 days old. Add this to your crontab and your session directory should stay nice and tidy.

Find and replace in multiple files with sed

Nice usage of find and sed to find and replace text. I used it to update the copyright notices in my projects.

Just change the *.pl part to the file type you want.

find . -name "*.pl" -exec sed -i "s/2012/2013/g" '{}' \;

Source: Wikia