source: http://ubuntuforums.org/showthread.php?t=625132 On the command line, you can use the “find” command to select certain files, and then use the “-exec” switch to cause some other command to be run on those files. So if you use “-exec rm” you will delete the files that are found. So, for example:
Code:
find -mmin +4 -exec rm {} +
will delete any files in the current directory (and sub-directories) that are older than 4 minutes. This is because the “-mmin +4” switch causes find to return files older than 4 minutes. There are other options, like “-mtime” that return files based on modified date in days. You can use + or – depending on what kind of behavior you are trying to achieve. For a more complete explanation of all the options, see the manual page: http://unixhelp.ed.ac.uk/CGI/man-cgi?find
Be careful when using the rm command! It’s usually a good idea to test your command first, before using it. So, for instance, use something like:
Code:
find -mmin +4 -exec ls {} +
which will just list the files that you are selecting for. If the list looks right, then you can switch the “ls” to “rm” in the command and it will delete the files.
and I noticed that they were being automatically rotated (access.log, access.log.1, etc.) and compressed with gzip (access.log.2.gz, etc.). This seems to be the default Ubuntu configuration. I wanted to make find out more, and I found this helpful article about Ubuntu logs, including Apache2 Log info and some basic log rotation info.
After reading through the info, I decided that I wanted to make a few changes. The log rotation happens via the brilliantly named logrotate command. It turns out that logrotate settings kept in 2 places. Lire la suite…
Crontabs is very useful when doing website maintenance. You can use this feature for the following purposes:
Deleting all files in a certain folder at regular intervals. If you accept user-uploaded files, then eventually it will clog your web hosting server. If you do not regularly delete these files, they will consume a lot of disk space and can slow down your website.
Deleting files of a specific type at regular intervals. You can also choose to delete files of a specific type, instead of deleting all of the files in the folder. If you have PHP, HTML and MP3 files together inside the folder, you can delete only the MP3 files.
Regularly backing up your MySQL database. This is one of the most important webmaster tasks. By using crontabs or the cron job feature, you can create a PHP script that will back up a selected MySQL database, and have it execute automatically executed at a specific, regular interval (e.g monthly, yearly, etc).
This tutorial will focus on creating a cron PHP script application, then configuring your cron hosting feature to execute these scripts automatically. Lire la suite…
I just had a problem to solve: Compare two server config files on two servers to make sure they’re the same. Rather than using scp to copy the file from one machine to another, I used ssh’s ability to run commands remotely to get the contents of the file and piped it into diff. Here’s an example: