cd /usr/ports && make clean

Hi all,

in order to save a few disk space I ran make clean on the whole ports tree, to see if I missed some clean of compiled ports. However this is going a little slow, is there a smarter way to do a clean on the ports without having to specify every single port to clean?
 
fluca1978 said:
is there a smarter way to do a clean on the ports without having to specify every single port to clean?
# rm -rf /usr/ports/*/*/work

Is usually a lot faster than:
# make -C /usr/ports clean
 
If you're low on disk space you could set WRKDIRPREFIX to somewhere with a lot more room. The "work" directories will end up there.

I've mine set to /tmp/build/. My /tmp/ is a 10GB tmpfs(5).
 
I've set WRKDIRPREFIX to /usr/obj and dedicated a partition for it, that way both the /usr/src builds and ports(7) use the same filesystem for temporary files.
 
Yes, but there can be reasons to do the steps separately. Like if you're looking for a file, or patching first. And sometimes things fail and leave leftover work directories. I use find(1):
Code:
find -X /usr/ports -name work -type d -depth 3 -prune -print -exec rm -rf {} \;
 
Dru said:
Seems like
Code:
make install clean
would be a lot simpler in the first place.

No?
Absolutely! But in some cases, especially after a major upgrade that went bad or if you follow experimental ports, you end up with leftovers.
Now, I know that most people will disagree here. But what I usually do to clean my messy desktop ports is:

[CMD=""] # cd /usr/ports && rm -rf * && portsnap extract[/CMD]

I never do it on a server though ;)
 
gkontos said:
Absolutely! But in some cases, especially after a major upgrade that went bad or if you follow experimental ports, you end up with leftovers.
Now, I know that most people will disagree here. But what I usually do to clean my messy desktop ports is:

[CMD=""] # cd /usr/ports && rm -rf * && portsnap extract[/CMD]

I never do it on a server though ;)

Careful, that also gets rid of all the distfiles that have been downloaded.
 
Hi,

Code:
# touch Clean
# echo #\!/bin/sh > Clean
# echo set -x >> Clean
# echo >> Clean
# chmod +x Clean
# find /usr/ports -name work -type d | \
  sed -e 's,/usr,cd /usr,g'  \
      -e 's,/work, \&\& make clean,g' >> Clean
# ./Clean

replace clean, in sed ,with package if you would like to keep built packages.
very stupid but it works.
 
gkontos said:
Absolutely! But in some cases, especially after a major upgrade that went bad or if you follow experimental ports, you end up with leftovers.

Exactly my problem. And since I'm running on a desktop, I don't have another disk with enough room to set the working directory for building ports.
Thanks everyone for suggestions.
 
Another way to save disk space is to delete obsolete distfiles:
# portmaster -t -y --clean-distfiles
 
wblock@ said:
Careful, that also gets rid of all the distfiles that have been downloaded.

And it also has the potential to backfire and destroy the entire system if you mistype command or use & accidentally instead of &&. You should never use rm -rf and * together. :) Much better to write the command like # rm -rf /usr/ports/* or even to combine the two into # cd /usr/ports/ && rm -rf /usr/ports/*

Or, if you really want to make things fast, put /usr/ports onto a separate filesystem, and just newfs(1) it to clear it. :)
 
phoenix said:
And it also has the potential to backfire and destroy the entire system if you mistype command or use & accidentally instead of &&. You should never use rm -rf and * together. :) Much better to write the command like # rm -rf /usr/ports/* or even to combine the two into # cd /usr/ports/ && rm -rf /usr/ports/*

Or, if you really want to make things fast, put /usr/ports onto a separate filesystem, and just newfs(1) it to clear it. :)

Of course what you are saying is true: there is a risk of destroying all the system with a rm. I think however this is always possible when using a rm so that you have to be really careful before hitting <enter>. And combining the two commands as # cd /usr/ports/ && rm -rf /usr/ports/* does not solves the problem of a mispelled & (moreover the first command is useless). Finally having the ports on a separate filesystem resilvered each time sounds like a bit too much to me.;)
 
phoenix said:
And it also has the potential to backfire and destroy the entire system if you mistype command or use & accidentally instead of &&. You should never use rm -rf and * together. :)
New users that use (t)csh might want to do this:

[cmd=]set rmstar[/cmd]

Code:
dice@molly:~/test>echo $SHELL
/bin/tcsh
dice@molly:~/test>touch test1
dice@molly:~/test>touch test2
dice@molly:~/test>touch test3
dice@molly:~/test>ll
total 0
-rw-r--r--  1 dice  dice  0 Dec  2 08:32 test1
-rw-r--r--  1 dice  dice  0 Dec  2 08:32 test2
-rw-r--r--  1 dice  dice  0 Dec  2 08:32 test3
dice@molly:~/test>rm *
dice@molly:~/test>
dice@molly:~/test>ll
total 0
dice@molly:~/test>touch test1
dice@molly:~/test>touch test2
dice@molly:~/test>touch test3
dice@molly:~/test>ll
total 0
-rw-r--r--  1 dice  dice  0 Dec  2 08:32 test1
-rw-r--r--  1 dice  dice  0 Dec  2 08:32 test2
-rw-r--r--  1 dice  dice  0 Dec  2 08:32 test3
dice@molly:~/test>set rmstar
dice@molly:~/test>rm *
Do you really want to delete all files? [n/y] 
dice@molly:~/test>
 
Back
Top