Getting Rid of Unwanted/Unneeded Files

This page is the results of the questions asked about how to remove unneeded/unwanted files on the PCLinuxOS forum here.

This ONLY involves cleaning old logs and other system stuff that is not needed.

Removing Unwanted/Unneeded files
These files can be found in the /var directory and are log and cache files. There are several way to get rid of these unwanted and unneeded files.

The first is to remove them by hand.

Open a console window and su to root

Now you can simply enter the following lines one at a time pressing enter after each line.

rm -rf /var/cache/cups/job* rm -rf /var/cache/fontconfig/* rm -rf $(find /var/spool -type f) rm -rf $(find /var/lib/spool -type f) rm -f $(find /var/log -type f -iname '*.old') rm -f $(find /var/log -type f -name '*.gz') rm -f $(find /var/log -type f -iname '*.[123456789]') cat /dev/null |tee $(find /var/log -type f -iname '*log') cat /dev/null |tee /var/log/dmesg cat /dev/null |tee /var/log/explanations cat /dev/null |tee /var/log/messages cat /dev/null |tee /var/log/wtmp cat /dev/null |tee /var/log/ConsoleKit/history

DO NOT just simply delete files in your /var/log folder, as some of these files are indeed needed by the system while it is running.

this is a list of some, of files that are required by the system while running.

dmesg, explanations, messages, wtmp and history.

You will note in the above list they start with the command cat /dev/null >

This command DOES NOT delete the file, it simply "empties" the contents of the file. Again DON'T delete these files.

The above is not only time consuming and error prone, but it takes a lot of time to enter and execute each and every line.

forum user "footstep11" brings a bit better solution by saving the commands to a filename called 'docleaning To do this simply copy the following lines and save them in your home directory as a file called docleaning.

rm -rf /var/cache/cups/job* rm -rf /var/cache/fontconfig/* rm -rf $(find /var/spool -type f) rm -rf $(find /var/lib/spool -type f) rm -f $(find /var/log -type f -iname '*.old') rm -f $(find /var/log -type f -name '*.gz') rm -f $(find /var/log -type f -iname '*.[123456789]') cat /dev/null |tee $(find /var/log -type f -iname '*log') cat /dev/null |tee /var/log/dmesg cat /dev/null |tee /var/log/explanations cat /dev/null |tee /var/log/messages cat /dev/null |tee /var/log/wtmp cat /dev/null |tee /var/log/ConsoleKit/history

Now to run this file, open a console window and su to root. At the prompt, type in the following command and then press enter

sh ./docleaning

While this is somewhat better, you still have to open a console, change to the root user and type in some code. I don't know about you, but I just don't remember, all of the possible commands that are required all the time.

Now comes CRON to the rescue
The nice part is we only need to set it up once and then let cron do all the work and we can forget about it.

Here's what we need to do to set it up.

Copy the following lines

@daily rm -rf /var/cache/cups/job* @daily rm -rf /var/cache/fontconfig/* @daily rm -rf $(find /var/spool -type f) @daily rm -rf $(find /var/lib/spool -type f) @daily rm -f $(find /var/log -type f -iname '*.old') @daily rm -f $(find /var/log -type f -name '*.gz') @daily rm -f $(find /var/log -type f -iname '*.[123456789]') @daily cat /dev/null |tee $(find /var/log -type f -iname '*log') && cat /dev/null |tee /var/log/dmesg && cat /dev/null |tee /var/log/explanations @daily cat /dev/null |tee /var/log/messages && cat /dev/null |tee /var/log/wtmp && cat /dev/null |tee /var/log/ConsoleKit/history

Save them as a file called root to /var/spool/cron. You will need to be the root user to save this new file.

1. Open a console window, become the root user. 2. Open nano (IE: nano /var/spool/cron/root) 3. Past the above lines into nano. 4. To save the file press ctrl + x 5. Answer Y when asked to Save modified buffer. Then press enter.

Your new file has been saved. You will need to set the permissions for your new file. Again as root in the console window, type in the following at the command prompt

chmod 600 /var/spool/cron/root

press enter. That's it.... You can now close the console window.

Now cron will do the job of cleaning your files automatically.