Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
useless files cleaner
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Fri Mar 09, 2007 2:09 am    Post subject: useless files cleaner Reply with quote

made that to clean unused library & programs i found in my gentoo, it's REALLY dangerous, so don't blame me if... blah blah blah

it's slow (yeah really) as it check if the file belong to a package, if not the file is move to /root/gentootrash.zip

logic is to - check all files in current directory with "equery b filename" to see if file belong to a package, if not file is considered good for trash. At least, revdep-rebuild will stop crying on old forget files you could have...

some notes:
1/ emerge zip gentoolkit
- needed programs
2/ don't run two versions of that program in the same time, as it will use the same tempfile (if you still don't know why, just don't do it)
3/ anyone care to do the same faster?
4/ don't forget, if your system is break by this program, blah blah blah...
5/ i use it in /usr/lib & /usr/bin to remove unwanted libs & programs, but if you do it will also remove programs that have been install by you ! (yeah even this one if you install it in /usr/bin :) )
6/ must be run as root (oh yes, re-read the /4 !)
7/ as i said if anything goes wrong, check /root/gentootrash.zip for a backup of the missing file
8/ paranoiacs could add # before the "zip...." line or remove that line to stay calm...
9/ don't run it everywhere, the program consider trash ANYTHING that isn't part of a package !!!
10/ if you still try it, well, i'm sure you understand the 4/ so

not really sure someone could enjoy it, but at least it has work for me, so it might help someone else...

Code:

#!/bin/bash
for i in $(ls *);
do
 src=$i
 echo "checking $i..."
 if test -f "$i"; then
 equery b "$i" > /var/tmp/mytemp 2<&1
 if test -s /var/tmp/mytemp; then
     echo "...is used by system"
 else
     echo "...is a useless file, archiving it"
     zip -9 -m /root/gentootrash.zip $i
 fi
 else
 echo "...is not a file"
 fi
done
Back to top
View user's profile Send private message
truc
Advocate
Advocate


Joined: 25 Jul 2005
Posts: 3199

PostPosted: Fri Mar 09, 2007 8:01 am    Post subject: Reply with quote

one thing that should drasticaly improve speed is to use qfile(from portage-utils) instead, you can even use the --orphans options which basicaly does the same as you script :)
_________________
The End of the Internet!


Last edited by truc on Fri Mar 09, 2007 12:40 pm; edited 1 time in total
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Fri Mar 09, 2007 11:43 am    Post subject: Reply with quote

omg truc you rock :D
This is exactly what i was looking for !!!

Code:

#!/bin/bash
qfile -o * | zip -y -9 -m /root/gentootrash.zip -@
Back to top
View user's profile Send private message
swimmer
Veteran
Veteran


Joined: 15 Jul 2002
Posts: 1330
Location: Netherlands

PostPosted: Sat Mar 10, 2007 11:58 am    Post subject: Reply with quote

Thank you very much indeed!!!
qfile slipped through my attention :-/

Greetz
swimmer
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Sat Mar 10, 2007 2:54 pm    Post subject: Reply with quote

:( grrr talking about useless tools !

let's see
Code:

cd /usr/bin

qfile * -o
i686-pc-linux-gnu-addr2line
i686-pc-linux-gnu-ar
i686-pc-linux-gnu-as
i686-pc-linux-gnu-c++filt
i686-pc-linux-gnu-gprof
i686-pc-linux-gnu-ld
i686-pc-linux-gnu-nm
i686-pc-linux-gnu-objcopy
i686-pc-linux-gnu-objdump
i686-pc-linux-gnu-ranlib
i686-pc-linux-gnu-readelf
i686-pc-linux-gnu-size
i686-pc-linux-gnu-strings
i686-pc-linux-gnu-strip

equery b i686-pc-linux-gnu-ar
[ Searching for file(s) i686-pc-linux-gnu-ar in *... ]

ls ar -l
lrwxrwxrwx 1 root root 20 mar 10 15:25 ar -> i686-pc-linux-gnu-ar

equery b /usr/bin/ar
[ Searching for file(s) /usr/bin/ar in *... ]
sys-devel/binutils-2.15.92.0.2-r1 (/usr/bin/ar -> ../i686-pc-linux-gnu/bin/ar)

ls -l ../i686-pc-linux-gnu/bin/ar
lrwxrwxrwx 1 root root 43 mar 10 15:25 ../i686-pc-linux-gnu/bin/ar -> /usr/i686-pc-linux-gnu/binutils-bin/2.17/ar

ls -l /usr/i686-pc-linux-gnu/binutils-bin/2.17/ar
-rwxr-xr-x 1 root root 53581 mar 10 15:25 /usr/i686-pc-linux-gnu/binutils-bin/2.17/ar


pff finally found the real ar file :)

ok see that, stupids tools find that /usr/bin/ar is a link to ../i686-pc-linux-gnu-bin/ar used by binutils
but consider ../i686-pc-linux-gnu/bin/ar is itself not use !!!

result: removing ../i686-pc-linux-gnu/bin/ar should be safe if you trust them, but we won't trust them on such a file that have i686-pc-linux-gnu in its name :P

result if you trust em:
Code:

rm /usr/bin/i686-pc-linux-gnu-ar
emerge grep
...
rm -f libgreputils.a
ar cru libgreputils.a closeout.o error.o exclude.o hard-locale.o isdir.o obstack.o quotearg.o savedir.o xmalloc.o xstrtol.o xstrtoumax.o
make[3]: ar : commande introuvable
make[3]: *** [libgreputils.a] Erreur 127
make[3]: quittant le répertoire « /var/tmp/portage/sys-apps/grep-2.5.1a-r1/work/grep-2.5.1a/lib »
make[2]: *** [all-recursive] Erreur 1
make[2]: quittant le répertoire « /var/tmp/portage/sys-apps/grep-2.5.1a-r1/work/grep-2.5.1a/lib »
make[1]: *** [all-recursive] Erreur 1
make[1]: quittant le répertoire « /var/tmp/portage/sys-apps/grep-2.5.1a-r1/work/grep-2.5.1a »
make: *** [all] Erreur 2

!!! ERROR: sys-apps/grep-2.5.1a-r1 failed.
Call stack:
 ...

:) see
Code:
make[3]: ar : commande introuvable


what's going wrong ?
Well, following the logic, it seems qfile & equery don't think the file is used by a package because in the package that file isn't present...

package says:
/usr/bin/ar -> ../i686-pc-linux-gnu/bin/ar

but in real it's
/usr/bin/ar -> i686-pc-linux-gnu-ar
i686-pc-linux-gnu-ar -> /usr/i686-pc-linux-gnu/bin/ar

i suppose we could consider it a packager builder bug?
Back to top
View user's profile Send private message
swimmer
Veteran
Veteran


Joined: 15 Jul 2002
Posts: 1330
Location: Netherlands

PostPosted: Sat Mar 10, 2007 3:22 pm    Post subject: Reply with quote

Hmpf - I ran into the same kind of bugs/problems with a lot of files in /usr/bin :-/

Do you file a bug?

Greetz
swimmer
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Sat Mar 10, 2007 3:24 pm    Post subject: Reply with quote

no, you really think we should ?
Back to top
View user's profile Send private message
swimmer
Veteran
Veteran


Joined: 15 Jul 2002
Posts: 1330
Location: Netherlands

PostPosted: Sat Mar 10, 2007 3:30 pm    Post subject: Reply with quote

krinn wrote:
no, you really think we should ?
I do indeed - it's not about our efforts to remove unused files anymore but about the lacking ability of qfile/equery to recognize and resolve symbolic links. Quoting the man page of qfile:
Quote:
FINDING FILES OWNERS
This is the default behavior of qfile. It will list the packages which own the files (or directories, or symlinks, or anything else Portage can install) you are querying.

Doesn't that say that it is able to handle symlinks?

What do you think?

Greetz
swimmer
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Sat Mar 10, 2007 3:39 pm    Post subject: Reply with quote

https://bugs.gentoo.org/show_bug.cgi?id=130004

well, a know bug i wasn't aware of, one more :)
Back to top
View user's profile Send private message
krinn
Watchman
Watchman


Joined: 02 May 2003
Posts: 7470

PostPosted: Sat Mar 10, 2007 3:48 pm    Post subject: Reply with quote

ok bug fill as the other was a previous (old) version
https://bugs.gentoo.org/show_bug.cgi?id=170276
Back to top
View user's profile Send private message
swimmer
Veteran
Veteran


Joined: 15 Jul 2002
Posts: 1330
Location: Netherlands

PostPosted: Sat Mar 10, 2007 4:04 pm    Post subject: Reply with quote

Thank you :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum