Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Portage & Programming
  • Search

[SOLVED] how do I get a list of orphaned files ?

Problems with emerge or ebuilds? Have a basic programming question about C, PHP, Perl, BASH or something else?
Post Reply
Advanced search
9 posts • Page 1 of 1
Author
Message
magowiz
Veteran
Veteran
User avatar
Posts: 1029
Joined: Thu Feb 17, 2005 12:38 pm
Location: Italy/Milan/Bresso
Contact:
Contact magowiz
Website

[SOLVED] how do I get a list of orphaned files ?

  • Quote

Post by magowiz » Tue Sep 01, 2009 1:16 pm

Hi,
since my package db was corrupted I reinstalled the whole gentoo system over my root partition without deleting files.
Since now I have some files that belongs to old installation ( packages merged before the db corruption and not merged in the new installation) I would like to get a list of theese files to :
reinstall packages I forgot to reinstall but that I need or simply remove files of packages that I don't need anymore .
Is there a way to get such a list ?
Last edited by magowiz on Wed Sep 02, 2009 6:56 pm, edited 1 time in total.
Top
V-Li
Retired Dev
Retired Dev
Posts: 618
Joined: Tue Jan 03, 2006 12:44 am

  • Quote

Post by V-Li » Tue Sep 01, 2009 2:25 pm

Code: Select all

 find / -type f | xargs qfile -o
May take a while and maybe you will exceed your command line length limit, adjust the argument of find and test the hierarchies separately.
Top
magowiz
Veteran
Veteran
User avatar
Posts: 1029
Joined: Thu Feb 17, 2005 12:38 pm
Location: Italy/Milan/Bresso
Contact:
Contact magowiz
Website

  • Quote

Post by magowiz » Tue Sep 01, 2009 3:16 pm

V-Li wrote:

Code: Select all

 find / -type f | xargs qfile -o
May take a while and maybe you will exceed your command line length limit, adjust the argument of find and test the hierarchies separately.
thank you very much , now I'm running it in /usr and I found some files
Top
jongeek
Tux's lil' helper
Tux's lil' helper
Posts: 135
Joined: Fri Jul 13, 2007 11:12 pm
Location: The Humid, Festering Swamps of Florida

  • Quote

Post by jongeek » Tue Sep 01, 2009 4:18 pm

V-Li is spot on, but I check my box periodically for orphans, and wrote a little script to help me out. You can check it out here: http://pastebin.com/m22712455.

The excludes and search variables control what is looked at and what is not. Very handy for running from cron once a month or so.
Top
V-Li
Retired Dev
Retired Dev
Posts: 618
Joined: Tue Jan 03, 2006 12:44 am

  • Quote

Post by V-Li » Tue Sep 01, 2009 5:13 pm

jongeek wrote:V-Li is spot on, but I check my box periodically for orphans, and wrote a little script to help me out. You can check it out here: http://pastebin.com/m22712455.

The excludes and search variables control what is looked at and what is not. Very handy for running from cron once a month or so.
Please don't pastebin such scripts, as they may get lost over time. For the archive here is a paste:

Code: Select all

#! /bin/bash                       

echo "start run @ " $(date "+%Y-%m-%d %H:%M") | tee /tmp/orphan-starttime

file01=/tmp/orphan01
file02=/tmp/orphan02

rm -f "${file01}" "${file02}"

search="/"
#search="/usr/share/doc/"

exclude="/bak /boot"
exclude="${exclude} /chroot /etc/gconf /etc/runlevels"
exclude="${exclude} /etc/ssl/certs"                   
exclude="${exclude} /lib/modules"                     
exclude="${exclude} /lost+found"                      
exclude="${exclude} /opt/wxwidgets /portagecrap /root"
exclude="${exclude} /usr/lib/perl5/site_perl /usr/lib/python2.5/site_packages"
exclude="${exclude} /usr/local/src"                                           
exclude="${exclude} /usr/portage"                                             
exclude="${exclude} /usr/share/mime"                                          
exclude="${exclude} /usr/src"                                                 
exclude="${exclude} /var"                                                     
exclude="${exclude} *.pyc *.pyo *.keep"                                       

predicate=""

for dir in ${exclude}
do                   
        predicate="${predicate} ${predicate:+"-o"} -path ${dir} -prune"
done

echo "building filelist ..."
echo find ${search} -xdev ${predicate} -o -print
     find ${search} -xdev ${predicate} -o -print > ${file01}

count=$(wc -l < ${file01})

echo "scanning ${count} files for orphans"

# This version gives progress information but is slow
#
#let i=1
#for file in $(cat ${file01})
#do
        #echo -ne "Checking ${i} of ${count} files...\r"
        #let i=$((i+1))
        #qfile -o "${file}" >> ${file02}
#done

# This version gives no progress information but is faster
#
echo "qfile'ing ..."
qfile -o -f ${file01} > ${file02}

echo
echo
echo "Found $(wc -l ${file02} | awk '{print $1}') orphans."
echo

cp -a "${file02}" /root/orphan-results.$(date "+%Y-%m-%d.%H%M")

rm "${file01}" "${file02}"

echo "finish run @ " $(date "+%Y-%m-%d %H:%M") | tee /tmp/orphan-stoptime

By they way, you could use mktemp to avoid overwriting files in /tmp by accident, even if this is a minor improvement.
Top
jongeek
Tux's lil' helper
Tux's lil' helper
Posts: 135
Joined: Fri Jul 13, 2007 11:12 pm
Location: The Humid, Festering Swamps of Florida

  • Quote

Post by jongeek » Tue Sep 01, 2009 5:41 pm

V-Li wrote: Please don't pastebin such scripts, as they may get lost over time.
Thanks, I'll post any scripts directly into the thread from now on. Didn't really think about the pastebin expiration when I posted.
V-Li wrote: By they way, you could use mktemp to avoid overwriting files in /tmp by accident, even if this is a minor improvement.
Cool, updated my script and testing it out now. Thanks for the tip !
Top
magowiz
Veteran
Veteran
User avatar
Posts: 1029
Joined: Thu Feb 17, 2005 12:38 pm
Location: Italy/Milan/Bresso
Contact:
Contact magowiz
Website

  • Quote

Post by magowiz » Wed Sep 02, 2009 1:09 pm

Do also the .ph files doesn't need to be reported as orphaned like .pyc or they are really orphaned files if they don't belong to any package ?
Top
jongeek
Tux's lil' helper
Tux's lil' helper
Posts: 135
Joined: Fri Jul 13, 2007 11:12 pm
Location: The Humid, Festering Swamps of Florida

  • Quote

Post by jongeek » Wed Sep 02, 2009 1:27 pm

Depending on where they are, sure. All of the *.ph files on my machine are under /usr/lib/perl5/site_perl, and are filtered by excluding that directory. In contrast, I have *.pyc files under /usr/lib/portage and elsewhere, which is why I have a separate filter for those as well as filtering /usr/lib/python/2.5/site_packages.
Top
magowiz
Veteran
Veteran
User avatar
Posts: 1029
Joined: Thu Feb 17, 2005 12:38 pm
Location: Italy/Milan/Bresso
Contact:
Contact magowiz
Website

  • Quote

Post by magowiz » Wed Sep 02, 2009 6:57 pm

jongeek wrote:Depending on where they are, sure. All of the *.ph files on my machine are under /usr/lib/perl5/site_perl, and are filtered by excluding that directory. In contrast, I have *.pyc files under /usr/lib/portage and elsewhere, which is why I have a separate filter for those as well as filtering /usr/lib/python/2.5/site_packages.
thanks for the explanation.

Thank you all, it's time to add the tag solved to the title ;) I hope someone else will find useful this topic like I do.
Top
Post Reply

9 posts • Page 1 of 1

Return to “Portage & Programming”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic