Friday, 12 June 2009

Linux: Safely deleting .rpmnew files

Just got on my hands on the new Fedora 11 today. I have to admit that I didn't get a chance to explore all the new things that Leonidas has brought along.

For starters, the feature that amazed me was the preupgrade script that magically downloaded everything, installed it and even changed my repos to point to correct ones for Fedora 11. And when I say repos, I do not mean only the basic ones, but also livna and RPM Fusion.

So the next thing that I had in my mind was to check all the .rpmnew files installed in my system and determine what was needed, so I started doing a search with a command like find / -name *.rpmnew -print, I ended up using diff and deleting the .rpmnew file that was identical to the original.

After comparing /usr/share/config/colors/Royal.colors.rpmnew, /usr/share/config/colors/40.colors.rpmnew, /usr/share/config/colors/Web.colors.rpmnew and /usr/share/config/colors/Rainbow.colors.rpmnew with their original versions and deleting all four of them, I decided that a little script could save me quit a lot of trouble. So after a little bit of digging I ended up with the following code:


# Locate all *.rpmnew files in your system and compares them with the 
# original files without the rpmnew extention. 
# Files are then compared using diff. If their contents are the same, then
# the .rpmnew version is removed.

RPM_NEW_LIST=`find / -name "*.rpmnew" -print 2>/dev/null`

    # Get the file without the .rpmnew extention
    # Compare it with the original
    # If diff's answer is not empty ...
    if [ -n "$DIFFERENT" ]; then
        echo "Please examnine files $ORIGINAL_FILE and $RPMNEW_FILE "
        # File is safe to remove
        # rm -f -v $RPMNEW_FILE
        echo "$RPMNEW_FILE file can safely be removed." 

I run this script as root on both my Fedora and CentOS 5.3 machines The simple version I have here will show you the files that are safe to delete and the files need your attention. If you like, you can uncomment the rm -fv line at the end of the script, but I would strongly advice against it.

Note: Sometimes rpm leaves out .rpmsave files as well so, if you are really into cleaning up your system, it is wise to search for these files also.