# How to make clean recursively?



## Chris_H (Feb 24, 2014)

Greetings all,
 I probably don't update my `src` && `ports` trees as often as I should. But sometimes during a long upgrade of all ports. Some things fail. Which leaves cruft in the failing port's directory. I can't possible keep track of this, because the text flies by too quickly. So in an effort to do some "housekeeping", I wanted to know if there was any(thing|way) to perform a `make clean` *recursively*. There used to be a port that did that, but I couldn't find it anymore. Is it possible to:

```
cd /usr/ports
make clean
```
and expect make() to perform the command recursively?

Thank you for all your time, and consideration.

--Chris


----------



## Engraf (Feb 24, 2014)

Yes, it is.


----------



## SirDice (Feb 24, 2014)

This is usually faster though: `rm -rf /usr/ports/*/*/work`.


----------



## Chris_H (Feb 24, 2014)

@Engraf
@SirDice
Thank you both for the replies!
@Engraf - Good to know, thanks. 

@SirDice - I thought about going that route. But it doesn't clobber all the other files a make creates (.blah-blah-extracted, etc...).
So I went a different route:

```
cd /usr/ports
find -s . -type d -name 'work' -exec ls -l '{}' \; -print >>/usr/FOUND
```
the results in the file FOUND clearly revealed the directories harboring work directories, in under 3 seconds. So I was able to `cd` into each of them, and `make clean`.
I thought about expanding upon it, by exec'ing a `make clean`, instead of `ls -l`. But I think I could do a more elegant job, and submit it to ports. 

Thanks again, to both of you! 

--Chris


----------



## SirDice (Feb 24, 2014)

Chris_H said:
			
		

> @@SirDice - I thought about going that route. But it doesn't clobber all the other files a make creates (.blah-blah-extracted, etc...).


Those are created inside the work directories.


----------



## Chris_H (Feb 24, 2014)

SirDice said:
			
		

> Chris_H said:
> 
> 
> 
> ...


Gah! You're right! You caught me.
I'm afraid I was in bit of a hurry. 

As always, thanks wblock@. Greatly appreciated.

--Chris

UPDATE:
Is it remotely possible that changing the `ls -l` I used for output in my script above, to `make clean` would actually work?
I'm afraid to try, as my scripting-foo isn't always the best.

--Thanks again.


----------



## wblock@ (Feb 24, 2014)

Huh?  I didn't say anything.  I use find(1) with -delete to delete work directories, but it makes me nervous because it uses an unqualified argument.


----------



## Chris_H (Feb 24, 2014)

wblock@ said:
			
		

> Huh?  I didn't say anything.  I use find(1) with -delete to delete work directories, but it makes me nervous because it uses an unqualified argument.


Greetings,
 I'm sorry, wblock@. Apparently I wasn't very clear.
As to my response to your reply which I quoted:
I was meerly thanking you for catching/informing me about the deleting of work, and related files, that SirDice had suggested.
As to the second part (under UPDATE:
I was asking you (or anyone) if the script I posted that I had used to find `work` directories, if modified from:

```
cd /usr/ports
find -s . -type d -name 'work' -exec ls -l '{}' \; -print >>/usr/FOUND
```
to

```
cd /usr/ports
find -s . -type d -name 'work' -exec make clean '{}' \;
```
would accomplish a `make clean` in any port directory, that had a `work` directory in it.

Apologies again. I hope I was clearer this time, and you can now understand me. 

--Chris


----------

