Ubuntu Forums ubuntu.com - launchpad.net - ubuntu help  

Go Back   Ubuntu Forums > The Ubuntu Forum Community > Other Community Discussions > Tutorials & Tips
Register Reset Password Forum Help Forum Council Search Today's Posts Mark Forums Read

Tutorials & Tips
The place to find Ubuntu related Tips & Tricks.

 
Thread Tools Display Modes
Old July 26th, 2009   #1
Gen2ly
Dark Roasted Ubuntu
 
Gen2ly's Avatar
 
Join Date: Nov 2006
Location: There and back again
Beans: 1,061
Package Management from the Command Line

Hello everybody. I am writing this for someone here that once did a good deed for me. If you are reading this (you know who you are), thank you, it is much appreciated.

I like to work from the command line. I find that once you get to know it, it is often quicker to do the tasks you need to do (especially as an administer). Here is a quick front-end to common management tasks (installing/removing pacakges, package information...) that you may do everyday on your machine. It's pretty well commented and include's help by just typing the command. I call it dm (debian management) and the syntax is simple:

Code:
dm <option> <*option2>
Option2 is often a package name but sometimes isn't needed. For example:

Code:
dm i openbox
Will install Openbox, and:

Code:
dm y
Will sync the respository database. Here's the script:

Code:
#!/bin/sh
# dm - shorthand frontend to debian management tasks

if [[ -z $@ ]]; then
  echo "dm <option> <*package> - debian management tasks
  c | clean     - delete .debs that can no longer be downloaded
  d | depclean  - remove unneeded dependencies
  i | install   - installs package and dependencies
  L | local     - install a local .deb package
  l | list      - list files installed by the package
  n | info      - package information
  o | owns      - lists package that owns a file (D-)
  q | query     - search for an installed package
  r | remove    - removes package and unneeded dependencies
  s | search    - searchs for package and package description
  u | update    - updates system
  v | distup    - distribution upgrade
  y | sync      - sync repository database
  daemonadd     - add daemon to run lvl <daemon> <defaults/??>
  daemonrm      - remove daemon from run levels
  purge         - removes package and configurations"
  exit
fi

case $1 in
  c | clean )     apt-get autoclean
#                  apt-get clean        # remove all pkg install sources
                  ;;
  d | depclean )  apt-get autoremove
                  ;;
  i | install )   shift
                  apt-get install "$@"
                  ;;
  L | local )     shift
                  dpkg -i "$@"
                  ;;
  l | list )      shift
                  dpkg -L "$@"
                  ;;
  n | info )      shift
                  apt-cache show "$@"
                  ;;
  o | owns  )     shift
                  dpkg -S "$@"
                  ;;
  q | query )     shift
                  if [ -z "$@" ]; then
                    dpkg -l; else
                    dpkg -l | grep "$@"
                  fi
                  ;;
  r | remove )    shift
                  apt-get remove "$@"
                  apt-get autoremove
                  ;;
  s | search )    shift
                  apt-cache search "$@"
                  ;;
  u | update )    apt-get update
                  apt-get upgrade
                  ;;
  v | distup )    apt-get dist-upgrade
                  ;;
  y | sync )      apt-get update
                  ;;
  daemonadd )     shift
                  update-rc.d "$@"
                  ;;
  daemonrm )      shift
                  update-rc.d -f "$@" remove
                  ;;
  purge )         shift
                  apt-get --purge remove "$@"
                  ;;
  * )             shift
                  apt-get "$@"
                  ;;
esac
I like to place my scripts in a hidden folder in the home directory:

Code:
mkdir ~/.bin
Make the script executable:

Code:
chmod +x ~/.bin/dm
And to have bash recognize the executable/script path, in your '~/.bashrc' (a hidden file in your home directory):

Code:
export PATH="~/.bin:$PATH"
Then reload the bash environment to have the new path recognized:

Code:
source ~/.bashrc
I'm using Debian at the moment so you'll notice there are no sudo arguments in the script. I typically need to do administrative tasks so I usually have a terminal window that is "su'd" to root and put the script and '~/.bashrc' there. You can do this by:

Code:
sudo su
Been a bit since I've used Ubuntu/Debian so any tips would be appreciated. I have tested the script though and does everything that I need to .

Last edited by Gen2ly; August 1st, 2009 at 05:44 PM..
Gen2ly is offline   Reply With Quote
Old July 27th, 2009   #2
Gen2ly
Dark Roasted Ubuntu
 
Gen2ly's Avatar
 
Join Date: Nov 2006
Location: There and back again
Beans: 1,061
Re: Package Management from the Command Line

Oy, fixed a typo in the list line.
Gen2ly is offline   Reply With Quote
Old July 29th, 2009   #3
Elep.Repu
A Carafe of Ubuntu
 
Elep.Repu's Avatar
 
Join Date: Jun 2009
Beans: 148
Re: Package Management from the Command Line

Thanks for the tip. I really couldn't find a good one, but now I have.
Good day.
Elep.Repu is offline   Reply With Quote
Old August 1st, 2009   #4
Gen2ly
Dark Roasted Ubuntu
 
Gen2ly's Avatar
 
Join Date: Nov 2006
Location: There and back again
Beans: 1,061
Re: Package Management from the Command Line

Glad you could put it to use Elep.Repu. Danke.
Gen2ly is offline   Reply With Quote
Old August 5th, 2009   #5
Gen2ly
Dark Roasted Ubuntu
 
Gen2ly's Avatar
 
Join Date: Nov 2006
Location: There and back again
Beans: 1,061
Re: Package Management from the Command Line

Oop, fixed some typos.
Gen2ly is offline   Reply With Quote
Old August 17th, 2009   #6
Gen2ly
Dark Roasted Ubuntu
 
Gen2ly's Avatar
 
Join Date: Nov 2006
Location: There and back again
Beans: 1,061
Re: Package Management from the Command Line

Removed tasksel option (didn't use anyway).
Gen2ly is offline   Reply With Quote
Old November 18th, 2009   #7
Gen2ly
Dark Roasted Ubuntu
 
Gen2ly's Avatar
 
Join Date: Nov 2006
Location: There and back again
Beans: 1,061
Re: Package Management from the Command Line

Cleaned up script a little bit more, added daemon option.
Gen2ly is offline   Reply With Quote

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 10:47 AM.


vBulletin ©2000 - 2010, Jelsoft Enterprises Ltd. Ubuntu Logo, Ubuntu and Canonical © Canonical Ltd. Tango Icons © Tango Desktop Project. bilberry