7

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?

3 Answers 3

8

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
6

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

1
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

1
  • 2
    This neither explains why it isn't working, nor what to do instead. See @Melebius answer for both. Commented Jul 28, 2019 at 10:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .