DaemonForums  

Go Back   DaemonForums > OpenBSD > OpenBSD General

OpenBSD General Other questions regarding OpenBSD which do not fit in any of the categories below.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 31st August 2019
ip6ix's Avatar
ip6ix ip6ix is offline
Fdisk Soldier
 
Join Date: Sep 2017
Posts: 66
Default Sorting installed packages by size

I was looking through the various man pages (pkg_* especially pkg_info(1)) trying to find an option where I could get a sorted list by size, of installed packages. pkg_info(1) has the "-s" option to output size, but no sorting.

Clearly some text munging was needed, with the use of pipes. Here's what I came up with:

Code:
pkg_info  -a -s | sed '/^$/d' | paste - - | sort -k 5 -n -r \
  | sed 's/^Information for inst://g' | awk '{print $3 "\t\t" $1};' \
  | numfmt --to=si
The first two parts get a list of installed packages plus size, removing empty lines, then I use paste(1) to join adjacent lines, do a reverse numeric sort on the 5th field, remove unneeded stuff, then print lines with fields in "size package" order.

numfmt(1) converts bytes to human-readable form and can be omitted if you don't have GNU coreutils installed, in which case the awk(1) command could be extended to do the conversion.

Pipes are one of the core components of the UNIX philosophy / way-of-doing-things, and one of the main reasons I love the OS family, particularly OpenBSD.
__________________
dc -e '[q]sa[ln0=aln256%Pln256/snlbx]sb12247225403800449909543746snlbxq'
Reply With Quote
  #2   (View Single Post)  
Old 31st August 2019
frcc frcc is offline
Don't Worry Be Happy!
 
Join Date: Jul 2011
Location: hot,dry,dusty,rainy,windy,straight winds, tornado,puts the fear of God in you-Texas
Posts: 335
Default

nice
Reply With Quote
  #3   (View Single Post)  
Old 31st August 2019
ibara ibara is offline
OpenBSD language porter
 
Join Date: Jan 2014
Posts: 783
Default

You should consider extending this into something can be made into a port.
Reply With Quote
  #4   (View Single Post)  
Old 31st August 2019
fvgit's Avatar
fvgit fvgit is offline
Spikes in tights
 
Join Date: May 2016
Location: perl -MMIME::Base64 -le 'print decode_base64("U2hlcndvb2QgRm9yZXN0")'
Posts: 314
Default

Very nice, @ip6ix!

On a vaguely related note, is there an easy way to find out which ports/packages make use of pledge(2) and unveil(2)?
Reply With Quote
  #5   (View Single Post)  
Old 31st August 2019
jggimi's Avatar
jggimi jggimi is offline
More noise than signal
 
Join Date: May 2008
Location: USA
Posts: 7,984
Default

Quote:
Originally Posted by fvgit View Post
Very nice, @ip6ix!
Indeed!
Quote:
On a vaguely related note, is there an easy way to find out which ports/packages make use of pledge(2) and unveil(2)?
The easiest way I know of is grep(1)ing the port Makefiles.
Reply With Quote
  #6   (View Single Post)  
Old 31st August 2019
fvgit's Avatar
fvgit fvgit is offline
Spikes in tights
 
Join Date: May 2016
Location: perl -MMIME::Base64 -le 'print decode_base64("U2hlcndvb2QgRm9yZXN0")'
Posts: 314
Default

Quote:
Originally Posted by jggimi View Post
Indeed!The easiest way I know of is grep(1)ing the port Makefiles.
I'll give that a try!

I knew I had seen this topic before! For a quick'n'dirty version of package by size sorting head over to solene@'s blog:
https://dataswamp.org/~solene/2018-0...ages-size.html

It needs to be said though, that the output from ip6ix's solution is aesthetically far more pleasing.

Code:
$ pkg_info -sa | paste - - - - | sort -n -k 5

Total size: 138561651
Information for inst:metaauto-1.0p3             Size: 21875
Information for inst:xsel-1.2.0p2               Size: 35153
Information for inst:quirks-3.124               Size: 36018
Information for inst:xclip-0.13p0               Size: 39741
Information for inst:xkbset-0.5p2               Size: 40172
Information for inst:libpaper-1.1.26            Size: 51956
Information for inst:libusb-compat-0.1.5p0              Size: 57898
(...)
vs.

Code:
pkg_info  -a -s | sed '/^$/d' | paste - - | sort -k 5 -n -r \
  | sed 's/^Information for inst://g' | awk '{print $3 "\t\t" $1};' \
  | gnumfmt --to=si

25M     pkglocatedb-1.5
23M     vim-8.1.1048p0-no_x11
21M     coreutils-8.31
10M     libxml-2.9.8p1
9.3M    lcms2-2.9
7.5M    libgphoto-2.5.22
6.2M    p7zip-16.02p5
(...)
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
reinstall all packages installed by pkg_add mfaridi OpenBSD Packages and Ports 4 5th March 2015 12:47 PM
Delete or replace all installed packages shep OpenBSD Packages and Ports 3 24th May 2010 01:31 AM
Listing of installed packages cyril OpenBSD Packages and Ports 2 9th June 2009 01:24 AM
sorting special characters gosha Programming 15 9th April 2009 02:29 AM
Sorting Packages JMJ_coder NetBSD Package System (pkgsrc) 3 20th May 2008 01:08 AM


All times are GMT. The time now is 03:46 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick