main | UNIX notes | UNIX Applications | links

Advanced UNIX Notes

Lot of things written here I only guess and don't know them surely, take them as "possible truth".

Last change: Aux 17, 2005 AD


Abbreviations etc.

^, C, ctrl
Control key.
cmd, cmds
Command, commands.



Shell is the program that interprets your commands like 'ls', 'gzip' etc. There are various shells: bash, tcsh ... with different syntax and capabilities.
Command line editing:/
- some of the key bindings available in Emacs work in shell as well (^A to get to the beginning of the line, ^R to search command history, ^O to search and repeat a sequence of commands ... ...)
Notes( see also commands):


Sh, bash: $> export VARIABLE='value' // no spaces around '='! Quotes prevent substitutions (for * etc). You can ommit "export" but it's better to write it there (see man export)
Ksh: $> setenv VARIABLE 'value'


Set title of a terminal windows (works at least for xterm and aterm):

$ export PS1="\[\033]0;New terminal title\007\]\u:\W\$ "

\[ ... \] tells to bash that the characters in between are unprintable and shouldn't be counted to the length of the prompt string
\033]0; ... \007 are special characters saying that the text in between shall become the terminal title


Useful Commands

(<text> = replace by your own; [text] = optional)

basename <name> [<suffix>] strips directory and suffix from filename. Ex: $> basename /bin/mkdir.exe .exe produces 'mkdir'. See dirname
dirname <name> strips non-directory suffix from file name. See basename.
set <list>
assigns elements of the list to the positional variables $1, $2 ... . $# contains the number of them. Attention: if the list is empty set prints all environmental variables, so make sure it is not empty.
shift removes the 1st positional variable, shifts the others to the left ($2 becomes $1) and decreases $#
tee [-a] <file> is used in pipe to copy what's going through to a file


BASH notes & goodies

Programmable completion(context sensitive)

Bash can offer completions that take into account the current context; it means, that typing xpdf <TAB> offers only *.pdf files and directories.

To enable it source the file /etc/bash_completion:

bash$ . /etc/bash_completion

Now you can see all completions that are defined (look at the end of each line for the executable/... name):

bash$ complete -p

You can also look at definitions of the completion functions (named '_ImageMagic', '_ant' ...):

bash$ declare -f

For more information see a more extensive description.

Administrating the system

Initialization of the OS

Process 'init' is the 1st one started on boot; it reads&executes /etc/inittab. Driven by it init calls other scripts to init. st, e.g. network. See /etc/init.d/README to learn what happens on startup. 
- see /etc, /etc/inittab.
- Autostart of a service: See /etc/inittab> look for 'initdefault' to learn what is the deault run level (let's call it LEVEL). Than 'ls /etc/rcLEVEL.d' - all scripts starting with 'S' are executed when the runlevel is entered. Thus if you don't want to run proftpd on startup and your default runlevel is 2, remove the file /etc/rc2.d/S<NN>proftpd where <NN> is a number (see 'ls rc2.d' to find it out).
- Mandrake: also /etc/rc.d, /etc/rc.d/init.d; the script /etc/rc.d/rc.sysinit is run at the very beginning (e.g. isapnp is run from there
- to see what has happened, see logs (eg. /var/log/syslog), program dmesg (Debian)

GUI: if it's set, init starts a display manager in the end, which displays a graphical login screen. Usually there are 3 disp. man.: xdm, kdm (KDE) and gdm (gnome) - search /etc/rcLEVEL.d for their startup scripts (S??xdm ...); all of them (on my system) check in /etc/X11/default-display-manager whether and the one written there starts (or none). This file may not contain anything else but the absolut path of the display manager to start.
If you want e.g gdm to offer more window managers on login screen (kde, gnome, twm ...) add for each of them a file into /etc/gdm/Sessions/ (having the same name as the manager); the file is a shell script that is run when user selects that manager. 

> Files


Prevent a services from beiing run at boot:

root# update-rc.d portmap remove

Sudo: Executing a program as another user

You can execute a program (run a command) as another user (e.g. root) using the command sudo. The proper permitions must be set in the file sudoers (see man sudoers). To allow user pepa run poweroff on your computer named popelnice which is in domain as a root (degault) without giving password , you would type into sudoers this:
pepa = NOPASSWD: /sbin/poweroff    # allow pepa to run poweroff as a root without password
To allow all users run "lp" and "cat" as the user printer on all systems (the password for printer will be required):
ALL    ALL = (printer) /bin/lp, /bin/cat        # all users on all systems run lp as printer; "ALL" must be in capitals!

To allow users to run /sbin/halt run visudo to edit /etc/sudoers.
Important: the changes will not apply until visudo is closed, even if you save the file.

Host_Alias HOST = computer_name    # without domain in my case
User_Alias FULLTIMERS = username1, username2
Cmnd_Alias HALT = /sbin/halt, /sbin/reboot
FULLTIMERS HOST = NOPASSWD: HALT    # do not require password to run halt commands
root2      ALL  = (ALL) ALL    # can run all commands via sudo 

A user can run it (I suggest to set an alias for the command via alias e.g. in .bash_profile):

username1$ sudo /sbin/halt

Mount points, floppy, CD etc.

Normally it's necessary to mount and afterwards umount floppy/CD if you want to use it (or use dos emulator dosemu to access them). Consider using autofs& automount for them (autofs startes automount daemon for certain mount points according to its configuration, see man autofs) or better for cdrom only (you could remove not umounted floppy). Gnome and KDE desktop environments can work around this.

Hardware, drivers and modules

To use a hardware (HW)(device) you need to 1) have a driver for it 2) set the driver and 3) load it. It can be either compiled into the kernel or it may be loaded as a module (not part of the kernel) when the system boots up. In the best case your system detects HW automatically,  has a driver for it and installs it so you don't need to care for anything, but HW producers' support for Linux is not very good and volunteers can't write all possible drivers so you may have problems (ideally buy ony HW supported by Linux).


Your device is not detected but a driver exists for it (look for it at,, etc.). OK, find out a configuration of the device in BIOS or in Windows if you use them too, get and install the driver and set it manually (see Modules below and some HOWTOs).


modinfo utility examines the object file module_file associated with a kernel module and displays any information that it can glean.
insmod installs a loadable module in the running kernel (according to instructions in /etc/modules.conf, usually). See man insmod.
modprobe and depmod utilities are intended to make a Linux modular kernel more manageable for everybody (manage dependencies ...).

Servers: Sound, fonts, printers, X server ...

Unix/Linux  is often server/client architecture. You need to run a server (=special program) for graphical user interface (X server, X window system), for using sound (e.g. Alsa), often it's used for management of fonts (needed to display special characters like "é"), likely you need one for printer ... .

For sound you need:

IsaPnP HW on Linux

The tools isapnp and pnpdump are used to enable Linux to work with the old ISA Plug and Play cards (e.g. Ethernet card).
To do (you need superuser rights for it):
1) get & compile isapnptools (the two mentioned above)
2) move isapnp into /sbin (it must be there for the system expects it to be there, as well as isapnp itself; otherwise some  things may not work)
3) $> pnpdump -i -o -c /etc/isapnp.conf        #  scan for isapnp cards and create a file woth possible configuration, that will be used by isapnp (it must be /etc/isapnp.conf). The flag -i is necessary, otherwise some cards may not be discovered. -c = select (uncomment) a configuration, -o = specify output file.
4) Edit the file  /etc/isapnp.conf to select (=uncomment) a configuration that works (check /proc/interrupts, /proc/ioports, /proc/dma to be sure there are no conflicts with resource allocation. Also remove any "(CHECK)" substring (they told me to do that ;)
5) $> /sbin/isapnp /etc/isapnp.conf   # set the cards and subscribe itself to be run on each boot (see /etc/rc.d/rc.sysinit).
6) if needed, load the appropriate modules (drivers for the cards, st. like "$> /sbin/modprobe ne io=0x240 irq=3" where the values correspond to those of the selected configuration in isapnp.conf; "ne" is the name of module for my Ethernet card).
7) At my system, the auto setting of isa PnP, which shall since now be done, doesn't work. I added the line "/sbin/isapnp /etc/isapnp.conf" at the very beginning of /etc/rc.d/rc.sysinit and it seems to set the PnP cards without causing possible resource conflicts. (">> /dev/null" could be added ...)

Example /etc/isapnp.conf file:
# $Id: unix_adv.html,v 1.5 2005/08/17 19:50:08 aja Exp $
# Release isapnptools-1.26
# 20.10.2002, 11:00 | setting of BIOS: PnP OS No

(READPORT 0x0273)

#     ANSI string -->Plug & Play Ethernet Card<--

(CONFIGURE RTL8019/4002810023 (LD 0
  (IO 0 (SIZE 32) (BASE 0x0240) )
  (INT 0 (IRQ 3 (MODE +E)))
 (NAME "RTL8019/4002810023[0]{Plug & Play Ethernet Card}")
  (ACT Y)
# End tag... Checksum 0x00 (OK)


# ANSI string -->ESS ES1869 Plug and Play AudioDrive<--

  (IO 0 (SIZE 8) (BASE 0x0800))
 (NAME "ESS0003/-1[0]{ESS ES1869 Plug and Play AudioDrive}")
  (ACT Y)

  (DMA 0 (CHANNEL 1))
  (DMA 1 (CHANNEL 0))
  (INT 0 (IRQ 5 (MODE +E)))
  (IO 0 (SIZE 16) (BASE 0x0220))
  (IO 1 (SIZE 4) (BASE 0x0388))
  (IO 2 (SIZE 2) (BASE 0x0330))
 (NAME "ESS0003/-1[1]{ESS ES1869 Plug and Play AudioDrive}")
  (ACT Y)

  (IO 0 (SIZE 1) (BASE 0x0201))
 (NAME "ESS0003/-1[2]{ESS ES1869 Plug and Play AudioDrive}")
  (ACT Y)
# End tag... Checksum 0x00 (OK)

# Returns all cards to the "Wait for Key" state

Example of loading the modules (run from /etc/inittab as "nt:35:once:/etc/initnet/snet":
#! /bin/sh
/sbin/modprobe ne io=0x240 irq=3  #    the same values as in isapnp.conf
/sbin/modprobe sb irq=5 io=0x220 dma=1


= loadable drivers etc. (must be loaded before being used, e.g. during the initialization-
- see above isapnp;
- see /sbin/lsmod (list loaded modules), modprobe ... (loads a module), /etc/rc.d/rc.modules (specifies aliases, resources?)




created by Jakub Holy 2003AD