A legible apt list --upgradable

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
WharfRat

A legible apt list --upgradable

Post by WharfRat »

Apt now has a feature to list the available upgrades apt list --upgradable, but it's bunched up which makes it difficult to read.

For anyone interested this is a simple alias to make it a little more legible.

Code: Select all

alias lupg='apt list --upgradable|sed "s/\// /"|column -t'
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
User avatar
slipstick
Level 6
Level 6
Posts: 1071
Joined: Sun Oct 21, 2012 9:56 pm
Location: Somewhere on the /LL0 scale

Re: A legible apt list --upgradable

Post by slipstick »

WharfRat wrote:Apt now has a feature to list the available upgrades apt list --upgradable, but it's bunched up which makes it difficult to read.

For anyone interested this is a simple alias to make it a little more legible.

Code: Select all

alias lupg='apt list --upgradable|sed "s/\// /"|column -t'
Is this a new feature added to the python script apt at /usr/local/bin which is executed when I type "apt" from the command line, or is this a feature in the "real" apt in /usr/bin ? Typing "apt list --upgradable" from the command line just brings up a list of commands for the python script because "list" is not one of the options.
EDIT: or is this a new feature in LM18 or 18.1 (I'm still using 17.3)
In theory, theory and practice are the same. In practice, they ain't.
User avatar
all41
Level 19
Level 19
Posts: 9520
Joined: Tue Dec 31, 2013 9:12 am
Location: Computer, Car, Cage

Re: A legible apt list --upgradable

Post by all41 »

slipstick wrote: EDIT: or is this a new feature in LM18 or 18.1 (I'm still using 17.3)
It works on my 18.1 but not on my 17.3 so it must be a new feature
Everything in life was difficult before it became easy.
WharfRat

Re: A legible apt list --upgradable

Post by WharfRat »

I noticed this feature beginning with 18, whatever the name was and also 18.1 when performing an apt update.

When it completes if there are any upgradeable packages a message is shown that they can be viewed with apt list --upgradable.

I've never noticed that with the 17 series. I checked 17.3 and there is no such apt option so it must have been introduced recently with Mint 18.
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: A legible apt list --upgradable

Post by xenopeek »

A nice idea but some packages have so many source repositories the new list becomes too wide. An example of the output with such a package (samba-common) that causes output to overflow to the next line:

Code: Select all

samba-common                   xenial-updates,xenial-updates,xenial-security,xenial-security  2:4.3.11+dfsg-0ubuntu0.16.04.3  all    [upgradable  from:  2:4.3.11+dfsg-0ubuntu0.16.04.1]
samba-common-bin               xenial-updates,xenial-security                                 2:4.3.11+dfsg-0ubuntu0.16.04.3  amd64  [upgradable  from:  2:4.3.11+dfsg-0ubuntu0.16.04.1]
samba-libs                     xenial-updates,xenial-security                                 2:4.3.11+dfsg-0ubuntu0.16.04.3  amd64  [upgradable  from:  2:4.3.11+dfsg-0ubuntu0.16.04.1]
smbclient                      xenial-updates,xenial-security                                 2:4.3.11+dfsg-0ubuntu0.16.04.3  amd64  [upgradable  from:  2:4.3.11+dfsg-0ubuntu0.16.04.1]
systemd                        xenial-updates                                                 229-4ubuntu16                   amd64  [upgradable  from:  229-4ubuntu12]
systemd-sysv                   xenial-updates                                                 229-4ubuntu16                   amd64  [upgradable  from:  229-4ubuntu12]
udev                           xenial-updates                                                 229-4ubuntu16                   amd64  [upgradable  from:  229-4ubuntu12]
util-linux                     xenial-updates                                                 2.27.1-6ubuntu3.2               amd64  [upgradable  from:  2.27.1-6ubuntu3.1]
uuid-runtime                   xenial-updates                                                 2.27.1-6ubuntu3.2               amd64  [upgradable  from:  2.27.1-6ubuntu3.1]
xdg-utils                      xenial-updates,xenial-updates                                  1.1.1-1ubuntu1.16.04.1          all    [upgradable  from:  1.1.1-1ubuntu1]
Also, the column command uses whitespace as a separator which causes "[upgradable from: VERSION]" to be put in three columns. Ai :)

I'm not saying this is better but it serves my needs. This command just shows the package name, new version and old version:
apt list --upgradable| sed -r 's/^([^/]*)\/[^ ]* ([^ ]*) [^ ]* [^:]*: (.*)]$/\1\/\2\/\3/' | column -s / -t
As compared to above the output isn't too wide with that command:

Code: Select all

samba-common                   2:4.3.11+dfsg-0ubuntu0.16.04.3  2:4.3.11+dfsg-0ubuntu0.16.04.1
samba-common-bin               2:4.3.11+dfsg-0ubuntu0.16.04.3  2:4.3.11+dfsg-0ubuntu0.16.04.1
samba-libs                     2:4.3.11+dfsg-0ubuntu0.16.04.3  2:4.3.11+dfsg-0ubuntu0.16.04.1
smbclient                      2:4.3.11+dfsg-0ubuntu0.16.04.3  2:4.3.11+dfsg-0ubuntu0.16.04.1
systemd                        229-4ubuntu16                   229-4ubuntu12
systemd-sysv                   229-4ubuntu16                   229-4ubuntu12
udev                           229-4ubuntu16                   229-4ubuntu12
util-linux                     2.27.1-6ubuntu3.2               2.27.1-6ubuntu3.1
uuid-runtime                   2.27.1-6ubuntu3.2               2.27.1-6ubuntu3.1
xdg-utils                      1.1.1-1ubuntu1.16.04.1          1.1.1-1ubuntu1
Or alternatively if you do want to see the source repositories in a column use this:
apt list --upgradable| sed -r 's/^([^ ]*) ([^ ]*) [^ ]* [^:]*: (.*)]$/\1\/\2\/\3/' | column -s / -t
Or further simplified just showing package name, source repository and new version:
apt list --upgradable| sed -r 's/^([^ ]*) ([^ ]*) .*$/\1\/\2/' | column -s / -t
Image
WharfRat

Re: A legible apt list --upgradable

Post by WharfRat »

xenopeek,

I haven't run into that source repository situation yet - but yea, the line wrapping doesn't look good at all :(

In addition, I now I have to toil over your sed line to figure out exactly what it's doing :D
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: A legible apt list --upgradable

Post by xenopeek »

The sed line is using a common trick I've picked up. Let's split its parts:

sed -r 's/^ - this tells sed to use extended regular expressions so we can more easily use groups, and starts the substitute command from the start of each line.

([^/]*)\/ - the next part matches any character that is not a forward slash and puts that in the first group and matches the forward slash next (this needs to be escaped by a backslash, hence the two slashes) and discards that. The round brackets are for grouping matches and we can refer back to groups later. The square brackets are for matching a character from a set of allowed characters. By putting the ^ character first in the square brackets we invert the set meaning match any character except the one given after the ^ character. This part grabs the package name.

[^ ]*_ - the next part (I've replaced the whitespace at the end by an underscore else it wouldn't display) works the same way except instead of matching any character that is not a forward slash and then discarding the forward slash after it, match any character that is not a whitespace and then discarding the whitespace after it. This part matches the package origin but in the first command I gave it doesn't group it so it is discarded.

([^ ]*)_ - the next part works the same and grabs the new version.

[^ ]*_ - the next part works the same and discards the package architecture.

[^:]*: (.*)] - the next part discards everything until the : character in the "[upgradable from: old-version]" bit of the output. It then discards the :_ , grabs the old version and discards the ] at the end.

$/\1\/\2\/\3/' - the final bit says we have to match till the end of the line and then replace the entire line by the first group, followed by a forward slash (needs to be escaped again, and so on for the second and third groups. Those were the package name, new version and old version. Using forward slash lets us tell the column command to use that as separator so any whitespace will be left untouched by it.
Image
WharfRat

Re: A legible apt list --upgradable

Post by WharfRat »

xenopeek,

Your explanation is greatly appreciated; Thanks for sharing. You saved me from a late night of head scratching.

You certainly are a sed line aficionado :D
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: A legible apt list --upgradable

Post by xenopeek »

All credits to the sed book :) http://www.sed-book.com/
Image
lmuserx4849

Re: A legible apt list --upgradable

Post by lmuserx4849 »

WharfRat wrote:Apt now has a feature to list the available upgrades apt list --upgradable, but it's bunched up which makes it difficult to read.

For anyone interested this is a simple alias to make it a little more legible.

Code: Select all

alias lupg='apt list --upgradable|sed "s/\// /"|column -t'
I'm on 17.3. Is --upgradable similar to:

Code: Select all

sudo apt-get -u -V  --assume-no upgrade
sudo apt-get -u -V  --assume-no upgrade | awk  '/^ / {printf ("%-40s %-30s %s\n", $1, $2, $4)}'
# I think I like this better
sudo apt-get -u -V  --assume-no upgrade | awk  '/^ / {print $1, $2, $4}' | column -t
It looks like it is missing the source repository...
Last edited by lmuserx4849 on Sat Jan 28, 2017 1:35 am, edited 1 time in total.
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: A legible apt list --upgradable

Post by xenopeek »

You can use /usr/bin/apt list --upgradable on Linux Mint 17.x. The normal apt command doesn't use /usr/bin/apt yet on Linux Mint 17.x, as it does on Linux Mint 18.x. Hence you would have to explicitly say you want to use /usr/bin/apt.
Image
lmuserx4849

Re: A legible apt list --upgradable

Post by lmuserx4849 »

xenopeek wrote:You can use /usr/bin/apt list --upgradable on Linux Mint 17.x. The normal apt command doesn't use /usr/bin/apt yet on Linux Mint 17.x, as it does on Linux Mint 18.x. Hence you would have to explicitly say you want to use /usr/bin/apt.
Brilliant. It didn't dawn on me that there would be 2 apt's on the system.

The output from the above command was not the same as Synaptic's "Installed (upgradable)". For example, "apturl-common" (see image), appears in the command output, but not in Synaptic's "Installed (upgradable)" output. The installed and latest version are the same and it shows "installed,upgradable" not just "upgradable" like "dbus"?

Synaptic's output has 9 packages, whereas the command has 23. If I remove all the lines with "installed, upgradable" from the command output and keep the ones that only say "upgradable" the output matches Synaptic's, with one exception, libdbus-1-3:i386 (1.6.18-0ubuntu4.4 1.6.18-0ubuntu4.5). It is in Synaptic's output but not the command output.
User avatar
xenopeek
Level 25
Level 25
Posts: 29597
Joined: Wed Jul 06, 2011 3:58 am

Re: A legible apt list --upgradable

Post by xenopeek »

I see the same thing but can't explain why it's listed as upgradable when the version is the same...
Image
lmuserx4849

Re: A legible apt list --upgradable

Post by lmuserx4849 »

The packages that appear in both apt list --upgradable and Synaptic's upgradable have a repository name of "trusty-updates" or "trusty-updates,trusty-security". The ones that appear only in apt list --upgradable show "rosa,now".

If I look at dbus (appears in both):
1.6.18-0unbuntu4.5 (trusty-updates)
1.6.18-0unbuntu4.4 (trusty-updates)
1.6.18-0unbuntu4 (trusty)

If I look at apturl-common (appears only in apt list ...):
0.5.2ubuntu4 (trust)
0.4.1ubuntu4.1mint1 (rosa)

I did spot this: apt list --upgradable gives lot of false positives
It looks like it is fixed in apt 1.0.8.

Currently:
/usr/bin/apt --version
apt 1.0.1ubuntu2 for amd64 compiled on Dec 8 2016 16:23:37
Locked

Return to “Scripts & Bash”