I'm trying to make a oneliner to be able to list all locked (forbidden to upgrade) packages in FreeBSD.

Normally, you issue this command:

pkg info -ak

It outputs list of all packages in system including locked and unlocked which isn't working for me as I only want locked ones. If I grep 'yes' it does exactly what I want:

pkg info -ak | grep yes

It outputs following:

nginx-devel-1.5.10             yes
php5-extensions-1.7            yes
php55-5.5.8                    yes

Now, what I want is to be able to edit that output a little bit by changing string 'yes' for following (adding package name w/ version omitted):

nginx-devel-1.5.10             locked, run: sudo pkg unlock nginx-devel
php5-extensions-1.7            locked, run: sudo pkg unlock php5-extensions
php55-5.5.8                    locked, run: sudo pkg unlock php55

I tried following unsuccessfully:

pkg info -ak | grep yes | sed s/yes/"locked - run: sudo pkg unlock $(pkg info -ak | grep yes | cut -d - f1-2)"/

While what I've tried isn't working I posted it just for you to get the idea what I'm trying to achieve.

pkg info -ak | grep -w yes | while read line; do packnum=`echo $line | awk '{print $1}'`; pack=`echo $packnum | awk 'BEGIN{FS=OFS="-"}{$NF=""; NF--; print}'` ; printf "%-33s%s\n" "$packnum" "locked, run: sudo pkg unlock$pack" ;done

I added -w option to your grep to avoid confusion with packages containing "yes" in their name string.

  • Hey @Slyx this is the output i get: nginx-devel-1.5.10 locked, run: sudo pkg unlock devel 1.5.10 So first package name field is missing and package version isn't omitted. Any chance of sorting those? Thanks man, appreciate it!
    – dzhi
    Feb 5 '14 at 19:31
  • Indeed ! I fixed the mistake, please see my edit !
    – Slyx
    Feb 5 '14 at 22:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.