# list of installed ports?



## wonslung (Jun 15, 2009)

is there a way to list all the installed ports on a system or in a jail?


----------



## vivek (Jun 15, 2009)

```
pkg_info
```
OR

```
pkg_info | less
pkg_info | grep -i php
```


----------



## ale (Jun 16, 2009)

vivek said:
			
		

> ```
> pkg_info | grep -i php
> ```


Don't pipe into grep, just use -x
	
	



```
pkg_info -Ix php
```


----------



## SirDice (Jun 16, 2009)

Another nice one to use is *pkg_version -v*.


----------



## ale (Jun 16, 2009)

SirDice said:
			
		

> Another nice one to use is *pkg_version -v*.


_portversion -v_ (from ports-mgmt/portupgrade) is a lot faster (about 6s vs. 70s here).


----------



## SirDice (Jun 16, 2009)

ale said:
			
		

> _portversion -v_ (from ports-mgmt/portupgrade) is a lot faster (about 6s vs. 70s here).



It does require an additional port. Pkg_version and pkg_info are part of the base OS. I also doubt the speed. It takes a while for portversion to collect data before it produces output. Pkg_version immediately starts producing output. Which probably accounts for the apparent difference in speed.


----------



## ale (Jun 16, 2009)

SirDice said:
			
		

> It does require an additional port. Pkg_version and pkg_info are part of the base OS.


Obviously, but if the OP is using portupgrade for upgrading his ports, portversion is free.



			
				SirDice said:
			
		

> I also doubt the speed. It takes a while for portversion to collect data before it produces output. Pkg_version immediately starts producing output. Which probably accounts for the apparent difference in speed.


Apparent?
	
	



```
$ time `pkg_version -v > /dev/null`

real	1m15.667s
user	0m41.320s
sys	0m12.968s

$ time `portversion -v > /dev/null`

real	0m7.332s
user	0m5.066s
sys	0m1.199s
```
(with 749 installed ports)


----------



## ale (Jun 16, 2009)

BTW, for a faster plain list (without version check) 
	
	



```
ls -1d /var/db/pkg/*
```


----------



## phoenix (Jun 16, 2009)

Don't forget that portupgrade (and hence portversion) require two separate databases be installed and kept up-to-date (portsdb and pkgdb).  All the portupgrade tools use these databases to pull their info, they don't use the /usr/ports/INDEX* or /var/db/pkg/* directly.

While it's not common, it is possible for the separate databases used by the portupgrade tools to become out-of-sync with the actual data in /var/db/pkg/* and/or /usr/ports/INDEX*, in which case you get incorrect results when using portversion.

Hence why, even though it may be slower, it's generally safer/more accurate to use pkg_version.  (Plus, it's always nice to use the built-in tools.)  

Just something to keep in mind.


----------



## jb_fvwm2 (Jun 17, 2009)

```
ls -lac /var/db/pkg
```
-l -a -c == "lack", for that reason, I always have used it,
even aliasing it to a shorter version (one word)
............
I wouldn't have posted it here, but its output seems
easier to read (the names are on the right of the screen).
(its usage here, maybe not in other instances).
......................

Also weekly it may be wise to

```
ls -lac /var/db/pkg | tee -a vardMODA.YR
```
 (month day year) 
and copy it elsewhere.   (You may be at another
computer wondering what ports you have installed and
have a backup copy available).


----------



## wonslung (Jun 17, 2009)

wow, thanks guys.


----------



## js (Nov 20, 2009)

Thanks for the info. Been meaning to have a useful easy to refer to list of what ports are installed that can be emailed somewhere else regularly, and this has done the trick perfectly.


----------



## FKEinternet (Mar 6, 2018)

FWIW, I'm upgrading from 10.3 to 11.1, and both *pkg_version* and *pkg_info* result in "_Command not found_" errors.


----------



## tobik@ (Mar 6, 2018)

FKEinternet said:


> FWIW, I'm upgrading from 10.3 to 11.1, and both *pkg_version* and *pkg_info* result in "_Command not found_" errors.


This thread is from 2009. It's `pkg version` and `pkg info` now.


----------



## SirDice (Mar 6, 2018)

Both tools didn't exist on 10.x either.


----------



## FKEinternet (Mar 6, 2018)

I did find a pointer to *pkg* in the mean time.  When this thread shows up in a search (which is how I found it), it will now have more useful information.  From somewhere else, the command I found to use is

*pkg query --all '%o %n-%v %R'*


----------



## tingo (Mar 6, 2018)

If one just want a list of installed packages (or ports) `# pkg info` will do that.


----------



## SirDice (Mar 6, 2018)

I would use `pkg version -vR` because this also tells me which packages need updating.


----------

