In a bash alias, how do I run "apt autoremove" automatically after "apt upgrade" only if needed?
0
votes
2
answers
92
views
I have two alias in my Debian's .bashrc:
alias upd='sudo apt update && apt list --upgradable'
alias upg='sudo apt upgrade'
Then I use
upd
to update and display all upgradable packages, and upg
to do the upgrade.
Sometimes the output of upgrade says something like "use 'apt autoremove' to remove them". I would like to append && sudo apt autoremove
to the second comand, if mentioned in the upgrade's output. Is this possible inside the alias? Or maybe I should just append it, and it won't do anything if not requested? (Still, it would be nice to learn the complete thing.) Or maybe I'll need to create a script that will be called in the alias? Also, I'd like to see the whole output too, and not just send it to another command input via pipe.
Asked by Rodrigo
(1894 rep)
May 25, 2025, 01:40 AM
Last activity: May 25, 2025, 03:26 PM
Last activity: May 25, 2025, 03:26 PM