Debian Tips and Tricks

From OptionC

Table of contents

Install

Networking

Current network information, all interfaces

ifconfig -a

The network interfaces in debian are configured in /etc/network/interfaces. There are scripts to bring things up and down (i.e. "ifup eth0"), although "ifconfig eth0 up" should work, too. This would be a basic configurations...

For using dhcp

 
#/etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet dhcp

Or for a static IP

 
#/etc/network/interfaces
# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
        address 192.168.0.100
        netmask 255.255.255.0
        gateway 192.168.0.1
        broadcast 192.168.0.255


Package management

Basic

  • How do I add sources to my respository list?

Debian stores information regarding which repositories to use in /etc/apt/sources.list. A very basic example (which tracks "stable" and the required security updates) looks like this.

#/etc/apt/sources.list
deb ftp://ftp.us.debian.org/debian/ stable main
deb-src ftp://ftp.us.debian.org/debian/ stable main

deb http://security.debian.org/ stable/updates main

Feel free to add more lines, either for redundancy or to add the ability to install packages from other sources (most likely this is done when a package you want it not maintained in debian). Every time you add a line, you need to

apt-get update
  • How to I "upgrade" my system (get the most current version of the packages for the release of Debian that you have installed)?
apt-get dist-upgrade
  • How do I install a .deb file by hand (as in, not using apt)?
dpkg -i PACKAGE_NAME.deb

You might see something like "PACKAGE_NAME has unmet dependencies and will not be installed. Try apt-get -f install?" If you do, it means that PACKAGE_NAME requires other packages that are not present on your system. Try doing what it says...

apt-get -f install


  • List installed packages
# dpkg --list | grep ii
  • Search for installable packages (SEARCH_TERM can appear in whole or part, in name or description)
# apt-cache search SEARCH_TERM
  • Don't install, just see what would happen
# apt-get -s install PACKAGE_NAME
  • Show detail information about an installed package
# dpkg --status PACKAGE_NAME

Source build stuff

  • Install all the dependencies required to build a package
# apt-get build-dep PACKAGE_NAME
  • Download the source to the current directory
# apt-get source PACKAGE_NAME

Alternate Repositories

Cloning

Finding your way around

Paging (as in, seeing text one page at a time)

"more" and "less" can both be used for looking at text one page at a time, but less allows you to scroll backwards, so I use it if it's available. For example, if you want to see a long config file (perhaps squid)

less /etc/squid/squid.conf

If you want to page the result of something, like the contents of a large directory

ls | less

How much space am I using...

On the mounted file systems?

df -h

In a particular directory (recursive)?

du -h

Where...

Are the configs?

/etc

Although some things run in at chroot()'d environment, so the files are usually in /var/lib/something, there is usually a symbolic link.

Are the logs?

/var/log

A good place to start tracking general issues is:

less /var/log/messages 

Or:

less /var/log/syslog

Find files by name...

find * -name FILE_NAME

Or pattern and case-insensitively:

find * -iname '*fn*'

List the file(s) containing STRING (recursively, case-insensitively)

grep -ir STRING *

For more information on any of these...

man COMMAND

What's running?

ps -A
ps aux
ps -e

How do I make it stop?

(Killing processes, stopping daemons)

For services and daemons:

/etc/init.d/DAEMON stop

For example, in order to stop bind9

/etc/init.d/bind9 stop

Try using "restart", "start", "reload" instead of "stop" :)


Kill (SIGTERM) a process by PID:

kill PID

Kill (SIGKILL) a process by PID:

kill -9 PID

Identify a process by name:

ps aux | grep NAME

Kill all processes named ABC:

killall ABC

Using Debian as a development environment

I'm not a developer, but I do build a lot of packages from scratch, so I tend to have a build environment I can fall back on. However, I've been asked "what's the magic button to get to install most of the stuff you need, like gcc and make?" Now, there is a meta-package but I can never remember it or find it. However, the package "build-essential" is for building debian packages.

"If you do not plan to build Debian packages, you don't need this package. Moreover this package is not required for building Debian packages.

This package contains an informational list of packages which are considered essential for building Debian packages. This package also depends on the packages on that list, to make it easy to have the build-essential packages installed.

If you have this package installed, you only need to install whatever a package specifies as its build-time dependencies to build the package. Conversely, if you are determining what your package needs to build-depend on, you can always leave out the packages this package depends on.

This package is NOT the definition of what packages are build-essential; the real definition is in the Debian Policy Manual. This package contains merely an informational list, which is all most people need. However, if this package and the manual disagree, the manual is correct."

Packages For Particular Purposes

  • Basic editor: gnotepad+, VIM
  • Thin Clients
    • Remote Desktop Client: rdesktop
    • VNC Client: xtightvncviewer
  • Multi-media stuff
    • Burning DVDs: growisofs (not that I actually recommend it, but you have to use something)
    • Watching video and movies: vlc, xine, mplayer (I added the videolan repository (http://www.videolan.org/vlc/download-debian.html) to /etc/apt/sources.list)
    • Image Viewing: feh (CLI), gqview (GTK)
    • Image Gallery (html): imageindex (I'm pretty sure this is the package I used for a while to update/maintain galleries. It was quite useful)
    • Debian and mplayer

.bashrc (default)

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything:
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
#export HISTCONTROL=ignoredups

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
    #alias dir='ls --color=auto --format=vertical'
    #alias vdir='ls --color=auto --format=long'
fi

# some more ls aliases
#alias ll='ls -l'
#alias la='ls -A'
#alias l='ls -CF'

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" -a -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm-color)
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
    ;;
*)
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    ;;
esac

# Comment in the above and uncomment this below for a color prompt
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD}\007"'
    ;;
*)
    ;;
esac

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profiles
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ]; then
#    . /etc/bash_completion
#fi