Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Minor Command Question

  1. #1
    Join Date
    Apr 2008
    Beans
    26
    Distro
    Ubuntu 10.04 Lucid Lynx

    Minor Command Question

    Can anyone explain exactly what the command below does?

    Code:
    sudo aptitude purge `dpkg -l | grep "^rc" | tr -s ' ' | cut -d ' ' -f 2`
    I found this "super clean" command while looking up the difference between clean and autoclean. I used this to reclaim some space, and it did so quite well. I want to recommend this to users, but I need to be able to fully explain what this does; I don't want to just tell a user to throw this into their terminal prompt without letting them know exactly what happens.

  2. #2
    Join Date
    Mar 2008
    Location
    The Burning Earth.
    Beans
    3,660

    Re: Minor Command Question

    If you don't want to recommend it with out understanding it entirely then why would you use it on your own system?
    God does not play dice with the universe - Albert Einstein
    Sure I do, I just use loaded dice. - warfacegod

    An open forum. Its a free for all. Check us out. https://openlinuxforums.org/

  3. #3
    Join Date
    Apr 2008
    Beans
    26
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Minor Command Question

    I have a virtual machine I can test unusual commands on, so if I nuke the VM, nothing is lost.

  4. #4
    Join Date
    Mar 2008
    Location
    The Burning Earth.
    Beans
    3,660

    Re: Minor Command Question

    I would opena Terminal Type "man" bfore each part of the code, Example:

    Code:
    man grep
    Enter. man is short for manual and will give a description of each command.
    God does not play dice with the universe - Albert Einstein
    Sure I do, I just use loaded dice. - warfacegod

    An open forum. Its a free for all. Check us out. https://openlinuxforums.org/

  5. #5
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Minor Command Question

    sudo = run the command as root
    aptitude = package manager
    purge = purge package
    `command` or $(command) = replace command name with the output of the command
    Code:
    man bash | less +/"Command Substitution"
    dpkg -l = list packages
    dpkg -l | grep "^rc" = list only the lines which begin with rc
    dpkg -l | grep "^rc" | tr -s ' ' | cut -d ' ' -f 2 = list only the second column (package name) of the lines

  6. #6
    Join Date
    Jun 2006
    Location
    Sunnyvale, CA
    Beans
    25
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Minor Command Question

    Another version:

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

    dpkg -l lists all packages installed or otherwise; the first two columns of each line indicate that packages state:

    Desired=Unknown/Install/Remove/Purge/Hold
    | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
    |/

    So, grep '^rc' says find the lines with "rc" at the beginning - the desired action is "Remove" and the status is "Cfg-files" (only config files exist on the system). For example:

    rc nvidia-glx-180 180.44-0ubuntu1 NVIDIA binary Xorg driver
    rc nvidia-settings 180.25-0ubuntu1 Tool of configuring the NVIDIA...

    The tr/cut or awk command just grabs the package name (nvidia-settings)

    aptitude purge removes the package/config from the system

  7. #7
    Join Date
    Apr 2008
    Location
    Australian in Germany
    Beans
    4,010
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: Minor Command Question

    I would have suggested the same as warfacegod.
    Michael

  8. #8
    Join Date
    Apr 2008
    Beans
    26
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Minor Command Question

    Awesome, thanks sisco311. I was a little confused after reading all the manual entries for the separate commands.

    Thanks for your input as well, warfacegod. I had somehow managed to completely forget about the man command. I guess this is what school does to me.

    This thread is solved.
    Last edited by MadDawg010; January 27th, 2010 at 01:23 AM. Reason: Spelling

  9. #9
    Join Date
    Jun 2006
    Location
    Sunnyvale, CA
    Beans
    25
    Distro
    Ubuntu 9.10 Karmic Koala

    Re: Minor Command Question

    And adding an -s to the aptitude command will simulate the purge just in case you're unsure:

    sudo aptitude -s purge ...

  10. #10
    Join Date
    Apr 2008
    Beans
    26
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Minor Command Question

    Ah, thanks for the additional input, gnack.

Page 1 of 2 12 LastLast

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
  •