How can I get a list with the packages selected by apt-get autoremove?
8,765
Solution 1
Since as per your comment you want to list only the packages that are going to be removed:
apt-get --dry-run autoremove | grep -Po '^Remv \K[^ ]+'
grep
command breakdown:
-
-P
: Interprets the given pattern as a PCRE (Perl Compatible Regular Expression) pattern -
-o
: Prints only the matched string instead of the whole line
Regex breakdown:
-
^
: matches the start of the line -
Remv
: matches aRemv
string -
\K
: excludes the previously matched substring from the matched string -
[^ ]+
: matches one or more characters not
$ apt-get --dry-run autoremove | grep -Po 'Remv \K[^ ]+'
libapache2-mod-php5
php5-readline
php5-cli
libonig2
libqdbm14
php5-json
php5-common
Solution 2
Actually you only need to filter the output of your
sudo apt-get autoremove --dry-run
command.
For instance you can do it with
sudo apt-get autoremove --dry-run | head -n 5 | tail -n 1
Related videos on Youtube
![Afonso Sousa](https://lh5.googleusercontent.com/-lPHF2emAKEw/AAAAAAAAAAI/AAAAAAAAABs/2_YUgpfVeP4/photo.jpg?sz=256)
Author by
Afonso Sousa
Updated on September 18, 2022Comments
-
Afonso Sousa almost 2 years
Is there any command that prints only the name of the packages that
apt-get autoremove
selects? I'm creating a script that updates the kernel, removes the old kernel and the unnecessary packages (apt-get autoremove
), but I want to print on the screen the list of packages that will be removed byapt-get autoremove
, how can I do this?-
Admin almost 9 yearsYou should just be able to get it to run
sudo apt-get autoremove -y
and it should autoremove anything needed to be removed... -
Doug almost 9 yearsTry reading here, [This may be of help.][1] [1]: serverfault.com/questions/433250/…
-
heemayl almost 9 yearsTo get the list of packages without removing them actually you can do
sudo apt-get --dry-run autoremove
-
Afonso Sousa almost 9 yearsI just want to get the name of the packages, not the entire output of the command....
-
-
Afonso Sousa almost 9 yearsYour command works too!! But I prefer the kos's command... But thanks in same!! :)
-
jarno over 8 years@GeekLynxAfonso, you don't need to use
sudo
with--dry-run
option. -
kos over 8 years@jarno Makes sense, the fact that it was probably not needed didn't occur to me. Thanks