"dpkg: error: requested operation requires superuser privilege". Cannot remove all configuration info from removed packages, sudo doesn't work

I want to run this command (see section 4 from here https://help.ubuntu.com/community/AptGet/Howto#Removal_commands):

dpkg -l | grep '^rc' | awk '{print $2}' | xargs dpkg --purge

I use sudo at the beginning but anyway I get an error:

user@user-desktop:~$ sudo dpkg -l | grep '^rc' | awk '{print $2}' | xargs dpkg --purge
[sudo] password for user:
dpkg: error: requested operation requires superuser privilege

Why sudo doesn't work? What else should I type?


try to login as root, to gain the super-power, you can do this by typing:

sudo -i

then write (copy/paste :: Ctrl + C / Ctrl + Shift + V <-- paste in terminal) your command in terminal, and it should work


sudo only applies to a single command, not the whole pipeline. In your case, the command ran as superuser was dpkg -l – which is not necessary.

On the contrary, the command really requiring the superuser access in your pipeline is dpkg --purge, so prepend sudo directly to it.

dpkg -l | grep '^rc' | awk '{print $2}' | xargs sudo dpkg --purge

By the way, awk can filter rows using regular expressions just like grep does, so you can save one command:

dpkg -l | awk '/^rc/{print $2}' | xargs sudo dpkg --purge

sudo -i dpkg -l | grep '^rc' | awk '{print $2}' | xargs dpkg --purge

This may run your command with ROOT priviliges. Sudo and root is different. Reference