Government Security
Network Security Resources

Jump to content

Photo

A Junk Cleaner


  • Please log in to reply
8 replies to this topic

#1 Kenny

Kenny

    Former Commander In Chief

  • Retired Admin
  • 6,747 posts

Posted 22 January 2008 - 04:38 PM

Quickly put this together to clear junk or archived files..as you know Linux will eat your HD up if your not careful ;)

run it from what ever directory as root ... handy for me over a gig recovered.. esp if you download or install loads of packages , or modules like me

#!/bin/bash
#Simple clear junk files..from selected paths
#
#Made this quick script to clear junk on the 6 distros currently am running for testing
#noticed lots of junk ie deb packages, files ,old slack modules and old logs
#make sure you are removing right files DOUBLE check PATHS are CORRECT
#Purpose:To free up space remove unwanted junk
#add directory as you wish
#Chmod u+x clear.sh
#Run as Root
#USAGE:$ ./clear.sh
#Script by Kenny GSO
#www.governmentsecurity.org/forum
#date:22/1/2008
#You may edit to your requirements..just be careful!!!!!
#Modify to current flavour
echo "Warning this will DELETE and Clean logs and old Cache etc from Set Paths "
echo -n "Are you SURE you want to continue. (y/n): "; read Answer
if [ $Answer = "n" ]; then
		echo "OK..Quiting Script Process Cancelled..."
		exit
fi
echo Cleaning old files............
echo "Please wait Files are being deleted.!!!!!!.." 
rm -f /var/cache/apt/archives/*.deb
rm -f /var/log/*.old
rm -f /var/log/*.gz
rm -f /var/log/*.1
echo Cleaned Listed Junk files.....
echo 1 = .deb old archives 
echo 2 = .old logs 
echo 3 = .gz old logs
echo 4 = .1 old logs
echo Finished...Exiting
exit
#END

Kenny aka ComSec

Please read the Forum Rules !!!

______________________

#2 Brabbit

Brabbit

    Private

  • Members
  • 14 posts

Posted 27 January 2008 - 12:52 PM

Thnkx kenny, for submiting this script...its is really useful...
it will lessen the time for deleting the archiv file manually one by one :)

so basicly what i have to do is go into a directory which has a lot of unwanted archiv files...and run the script as root, ans it will get rid off all the files that are archived?
If drinking and driving is illegal, why do bars have parking lots? :P

#3 Kenny

Kenny

    Former Commander In Chief

  • Retired Admin
  • 6,747 posts

Posted 27 January 2008 - 09:24 PM

run it from what ever directory you put the script in ..home folder , desktop anywhere...it dont have to be in the same junk files folder

the path is in the script you can change the paths to whatever directory you want to clean out...mine is an example to clean up ubuntu or debian based paths

amend it to whatever linux your using... fedora , slackware , SuSe etc

run it as root.. it will clean the files out
Kenny aka ComSec

Please read the Forum Rules !!!

______________________

#4 DarkJester

DarkJester

    Corporal

  • Members
  • 151 posts

Posted 28 January 2008 - 08:20 AM

works as advertised on my debian etch system also kenny ive noticed at least on my system and im wondering if you have the same "issue"(as i belive you use a similer setup ubuntu if i rember correct) when editing a file with gedit (i guess) i get a "backup file" named <file>.<ext>~ how ever a serach of the disk only returns these files in the current directory just wondering if youve got a solution to this that i could "obtain" or maybe we could work on it together
<Jesta> MJC u back me up init
<Jesta> i r a good boy yes
<MrjohnnyCochran> depends...
<Jesta> thats an open ended statment
<MrjohnnyCochran> are there girls? :P
<Jesta> mjc yes
<Jesta> lots
<MrjohnnyCochran> then ur not a good boy
* Jesta resembles that remark

^--<3s kitty aka erica

#5 Kenny

Kenny

    Former Commander In Chief

  • Retired Admin
  • 6,747 posts

Posted 28 January 2008 - 10:22 AM

i tend to use nano or pico and edit from the terminal i dont often use gedit...so what your sying is it will create 2 files editing with gedit..and the second file will end ...say file.sh~

not seen that...but will take a look see what happens...

re OS

yes using ubuntu\kubuntu mostly...and do in fact have 7 now different distro's fully installed on 3 boxes fedora 8 , slax , slackware , mepis , mutagenix and zenwalk...and about 4 in virtualbox setups... trying to find one or two that i like best for permanent use...still not decided yet...spoilt for choice ;)
Kenny aka ComSec

Please read the Forum Rules !!!

______________________

#6 DarkJester

DarkJester

    Corporal

  • Members
  • 151 posts

Posted 28 January 2008 - 01:00 PM

ive been thru a few distros myself including but not limited to redhat/fedroa centos debian (k)ubuntu gentoo mandrake suse and slackware

see attached image for discription of the ~ "thing" it is prtty much what you said with a few "interesting" features

Attached Files


<Jesta> MJC u back me up init
<Jesta> i r a good boy yes
<MrjohnnyCochran> depends...
<Jesta> thats an open ended statment
<MrjohnnyCochran> are there girls? :P
<Jesta> mjc yes
<Jesta> lots
<MrjohnnyCochran> then ur not a good boy
* Jesta resembles that remark

^--<3s kitty aka erica

#7 Kenny

Kenny

    Former Commander In Chief

  • Retired Admin
  • 6,747 posts

Posted 29 January 2008 - 03:22 AM

yes reproduced it like yours... seems if you have the show hidden files ticked and you make amendments to a file you made execute it will save the original file as a back up ... i made testx.sh then edited after i chmod i got a copy of the original hidden and the new wrote over file...noticed a few files i edited after chmod doing the same...see directory highlited in the other window...weird but handy if you want the original back....then again it can be classed as eating up space so i assume it or they can be deleted...will get back and let you know

see image

Attached Files

  • Attached File  snap.png   419.26KB   95 downloads

Kenny aka ComSec

Please read the Forum Rules !!!

______________________

#8 Kenny

Kenny

    Former Commander In Chief

  • Retired Admin
  • 6,747 posts

Posted 29 January 2008 - 03:50 AM

done a test...seems txt files or any that are edited will create the ~ hidden file... and can be deleted...so assuming this

by adding examples directory and file type ie

rm -f /home/test/files/*.sh~

or

rm -f /home/test/files/*.txt~

and so on..paths depending were your most edited files will duplicate...you can get rid of them

others to note are yet another duplicate saved file.. that ends in example clean.sh.save so amend the script to add more as you find them
Kenny aka ComSec

Please read the Forum Rules !!!

______________________

#9 MRK

MRK

    Private

  • Members
  • 4 posts

Posted 19 February 2008 - 02:04 AM

@first post

Nice, thanks :lol:
[Edit: Glyph: NO thanks post. Read the forum Rules]
[Edit: Glyph: Rule 15. NO image tags in sig]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users