3

I would like to get all the packages that contain the "nvidia" substring in their name, to sum up their size and print the total size in megabytes. To do so I have written the following oneliner:

dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n | grep nvidia | awk -F' ' '{sum+=$1}END{print sum/1024;}'

But, how can I beautify it, make it as short as it is possible to be, keeping the functionality?

It is crooked-written for now, as you can see.

4

You can filter using dpkg-query itself, which means you don’t need to output the package name, and you don’t need to sort either:

dpkg-query -Wf '${Installed-Size}\n' '*nvidia*' | awk '{sum+=$1}END{print sum/1024;}'
| improve this answer | |

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.