Results 1 to 4 of 4

Thread: Understanding linux, sudo command related

  1. #1
    Join Date
    Dec 2009
    Location
    Argentina
    Beans
    188
    Distro
    Lubuntu 14.04 Trusty Tahr

    Understanding linux, sudo command related

    Hello,
    I have found a command in https://help.ubuntu.com/community/AptGet/Howto, which is
    Code:
    dpkg -l | grep '^rc' | awk '{print $2}' | xargs dpkg --purge
    .
    The website states that
    While there is no built in way to remove all of your configuration information from your removed packages you can remove all configuration data from every removed package with the following command.
    .
    So I tried the command, it returned
    dpkg: error: requested operation requires superuser privilege
    . So I tried to use sudo..., but it returned:
    Code:
    dpkg: error: requested operation requires superuser privilege
    .
    I sought help in a chess forum and the guy told me to open xterm with sudo and then type the command. This returned:
    Code:
    dpkg: error: --purge needs at least one package name argument
    
    Type dpkg --help for help about installing and deinstalling packages[*];
    Use 'apt' or 'aptitude' for user-friendly package management;
    Type dpkg -Dhelp for a list of dpkg debug flag values;
    Type dpkg --force-help for a list of forcing options;
    Type dpkg-deb --help for help about manipulating *.deb files;
    
    Options marked[*] produce a lot of output - pipe it through 'less' or 'more' !
    .
    He then told me to try the normal LXterminal and to add "sudo" just before "xargs". This returned
    Code:
    dpkg: error: --purge needs at least one package name argument
    
    Type dpkg --help for help about installing and deinstalling packages[*];
    Use 'apt' or 'aptitude' for user-friendly package management;
    Type dpkg -Dhelp for a list of dpkg debug flag values;
    Type dpkg --force-help for a list of forcing options;
    Type dpkg-deb --help for help about manipulating *.deb files;
    
    Options marked[*] produce a lot of output - pipe it through 'less' or 'more' !
    .
    Finally I found the "fix" myself: "sudo su" and then type the command, that removed a few packages.

    I am trying to understand why "sudo" failed in the first place, why "sudo su" was required and why placing "sudo" in front of "xargs" gave exactly the same result as being root in Xterm and still failed to execute the command as it should. I would appreciate some help and explanations on what's going on.
    Thank you very much.

  2. #2
    Join Date
    Aug 2011
    Location
    52.5° N 6.4° E
    Beans
    6,821
    Distro
    Xubuntu 22.04 Jammy Jellyfish

    Re: Understanding linux, sudo command related

    dpkg -l lists all packages with status other than un (+ a header). These are piped in:
    grep, which filters it to get only the lines starting with rc, that is, the uninstalled packages with remaining config files, which is then piped into
    awk, picking the second word, wich is the package name, which is piped into
    xargs, which adds them to the command line of dpkg --purge.

    The first try didn't succeed becaus you were not root. Adding sudo to the front of the command ran only dpkg -l with root privileges, which didn't help. Running it from a root shell or inserting sudo to get xargs sudo dpkg --purge runs dpkg --purge <arguments> with root privileges, which is what you needed. They should both give the same result. I think this should have worked, except when there were no packages with remaining configuration files, which would lead to the error messages you recieved ("needs at least one package name"). If you are positive there were packages to be purged, then I don't know.

  3. #3
    Join Date
    Dec 2009
    Location
    Argentina
    Beans
    188
    Distro
    Lubuntu 14.04 Trusty Tahr

    Re: Understanding linux, sudo command related

    Ok I see, thank you very much.
    Indeed now "sudo su" + the command, returns exactly the same message than sudo in front of xargs.
    Problem solved, I suppose.

  4. #4
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    awk

    Also, if you are using awk then it is rare to need grep, too. Awk has most of the same capabilities.

    Code:
    dpkg -l | awk '/^rc/ {print $2}'
    dpkg -l | awk '$1 == "rc" {print $2}'

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •