# PKGNG: Delete all packages containing...



## xegeneric (Nov 8, 2013)

Hello,

I wrote a simple script that glues `pkg info` and `pkg delete` together. In my case, I switched desktop systems from Xfce, and tried to work out a way to just delete all packages in the database with "xfce" in their names. I accomplished this, and incarnated it in this bash script. Just run the script, input a string for `pkg info` to parse, `y` or `n` at the prompt and PKGNG will remove all packages containing your string.

Here it is:


```
#!/usr/local/bin/bash

echo "Delete all packages containing...: \n"
read arg

pkgname=$(pkg info | grep "$arg")

pkg delete $pkgname
```

It should be said that this script *should not be used* unless you are *absolutely sure* you know you will not *accidentally delete dependencies of packages that you will still need.* If you run the script and PKGNG yells at you because dependencies are still required by other packages, review said dependencies and double check that you will not bork anything. To stop PKGNG complaining, modify this line of the script:


```
pkg delete $pkgname
```

to...:


```
pkg delete -f $pkgname
```

This will *f*orce PKGNG to remove the installed packages in question. 

Hopefully someone out there has a use for this!


----------



## kpa (Nov 8, 2013)

Why can't you use the -x flag of pkg-delete(8)? Like:

`pkg delete -fx xcfe`


----------



## phoenix (Nov 8, 2013)

Be sure to add -i to any delete commands using -f. Especially when using -x   That will show you the command and ask if you really want to run it. Gives you an opportunity to see what will get removed, and a chance to back out before it's too late.

Although, I believe pkg delete may default to -i now?


----------



## xegeneric (Nov 9, 2013)

Well, thanks guys! I read the pkg manual page, but I must have overlooked those switches. Phoenix I believe you're correct that pkg delete defaults to -i. When I ran the script after adding p-f, I got a package list followed by a y/N prompt.


----------

