Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
user:vvkjndl:opkg-list-packages-sorted [2020/10/10 19:46] – created vvkjndluser:vvkjndl:opkg-list-packages-sorted [2020/10/30 15:24] vvkjndl
Line 1: Line 1:
-<file opkg-list-installed-packages-sorted-by-size>+===== Opkg List All Installed Packages Sorted by Size ===== 
 + 
 +:!: This script is inspired by [[https://openwrt.org/user/yeti/opkg-list-user-installed-packages]]. 
 + 
 +:!: This script will list all packages instead of listing only user-installed packages. 
 + 
 +Three conditions are applied in determining a package size (in order, if the first one is not applicable then the next one is used): 
 + 
 +  * Calculate size of all files in package list file ''/usr/lib/opkg/info/packagename.list''. ''du -k'' command is used. (fast and accurate) 
 +  * Calculate package size using opkg itself. ''opkg info packagename'' command is used. (CPU-intensive and less-accurate as actual files residing on filesystem are probably consuming more space) 
 +  * Mark package size as unknown using ''-.-''
 + 
 +:!: This script should work on base installation without requiring any additional packages to be installed. 
 + 
 +<file bash opkg-list-installed-packages-sorted-by-size.sh>
  
 #!/bin/sh #!/bin/sh
Line 11: Line 25:
         if [[ -z "$packagefiles" ]]         if [[ -z "$packagefiles" ]]
         then         then
-                packagesizeb=$(opkg info $packagename | grep Size | sed 's/Size\:\ //g')+                packagesizeb=$(opkg info $packagename | grep Size\: | sed 's/Size\:\ //g')
                 if [[ -z $packagesizeb ]]                 if [[ -z $packagesizeb ]]
                 then                 then
                         echo -e "-.- KB \t\t$packagename"                         echo -e "-.- KB \t\t$packagename"
                 else                 else
-                        packagesizekb=$(opkg info $packagename | grep Size | sed 's/Size\:\ //g' | awk 'END {printf "%.02f\n", $1/1024}')+                        packagesizekb=$(opkg info $packagename | grep Size\: | sed 's/Size\:\ //g' | awk 'END {printf "%.02f\n", $1/1024}')
                         printf '%-16s' "$packagesizekb KB"; printf '%s\n' "$packagename"                         printf '%-16s' "$packagesizekb KB"; printf '%s\n' "$packagename"
                 fi                 fi
  • Last modified: 2021/08/10 08:28
  • by tmomas