Speed up find -exec

Have you ever run a command like this one?

find -type f -mtime +7 -exec rm -f {} \;

Have you ever run it on a hundred thousand files?  And on millions?  Did the command run for minutes, maybe hours?  This is normal as find creates “fork” processes on the rm command for each file to delete and that can become very long when there are tons of files.

To speed it up, and when I say speed it up, I mean 5 times faster or more sometimes, depending on the hardware in the system.  You can easily modify the command like this:

find -type f -mtime +7 | xargs rm

The reason why it is faster is that the rm command will be run only once with all the file names in parameter instead of being called many times with for a single file each time.

I hope this will help you accelerate your work and/or scripts!

Find install date of your linux machine

One day I had to review which servers were becoming old at my job and needed to be replaced before something bad happens.  It happenned that I was not there when these servers were first installed and the tech did not write this info down anywhere…

After searching a bit, I found a few responses, the first one is related to RPM-Based distros directly like CentOS, RHEL, etc.:

# rpm -qi basesystem

Note: On some types of V-Servers, this command gives the install date of the Master server and on others, it gives the right date.

The second answer I found was more generic but depends on the fact that this file could be replaced since the install.  It happens that virtually all distros of linux generate host ssh keys within their startup script (right after installation, at first boot) and these files are usually never messed with:

# ls -l /etc/ssh/

Hope this helped a bit!  It worked for me in all cases I have tested it so far…