# UNIX Basics ***Rewritten by Chris Shumway. *** [[!toc levels=3]] ## Synopsis The following chapter will cover the basic commands and functionality of the DragonFly operating system. Much of this material is relevant for any UNIX®-like operating system. Feel free to skim over this chapter if you are familiar with the material. If you are new to DragonFly, then you will definitely want to read through this chapter carefully. After reading this chapter, you will know: * How to use the ***virtual consoles*** of DragonFly. * How UNIX file permissions work along with understanding file flags in DragonFly. * The default DragonFly file system layout. * The DragonFly disk organization. * How to mount and unmount file systems. * What processes, daemons, and signals are. * What a shell is, and how to change your default login environment. * How to use basic text editors. * What devices and device nodes are. * What binary format is used under DragonFly. * How to read manual pages for more information. ## Virtual Consoles and Terminals DragonFly can be used in various ways. One of them is typing commands to a text terminal. A lot of the flexibility and power of a UNIX® operating system is readily available at your hands when using DragonFly this way. This section describes what ***terminals*** and ***consoles*** are, and how you can use them in !DragonFly. ### The Console If you have not configured DragonFly to automatically start a graphical environment during startup, the system will present you with a login prompt after it boots, right after the startup scripts finish running. You will see something similar to: Additional ABI support:. Starting cron. Local package initialization:. Additional TCP options:. Wed Feb 18 17:53:48 GMT 2009 DragonFly/i386 (Amnesiac) (ttyv0) login: The messages might be a bit different on your system, but you will see something similar. The last two lines are what we are interested in right now. The second last line reads: DragonFly/i386 (Amnesiac) (ttyv0) This line contains some bits of information about the system you have just booted. You are looking at a ***DragonFlyBSD*** console, running on an Intel or compatible processor of the x86 architecture[(1)](#FTN.AEN1036). The name of this machine (every UNIX machine has a name) is `Amnesiac`, and you are now looking at its system console--the `ttyv0` terminal. Finally, the last line is always: login: This is the part where you are supposed to type in your username to log into DragonFly. The next section describes how you can do this. ### Logging into DragonFly DragonFly is a multiuser, multiprocessing system. This is the formal description that is usually given to a system that can be used by many different people, who simultaneously run a lot of programs on a single machine. Every multiuser system needs some way to distinguish one user from the rest. In DragonFly (and every other kind of UNIX and UNIX-like operating system), this is accomplished by requiring that every user must log into the system before being able to run programs. Every user has a unique name (the username and a personal, secret key (the password). DragonFly will ask for these two before allowing a user to run any programs. Right after DragonFly boots and finishes running its startup scripts[(2)](#FTN.AEN1060), it will present you with a prompt and ask for a valid username: login: For the sake of this example, let us assume that your username is `john`. Type `john` at this prompt and press **Enter** . You should then be presented with a prompt to enter a password: login: john Password: Type in `john`'s password now, and press **Enter** . The password is not echoed! You need not worry about this right now. Suffice it to say that it is done for security reasons. If you have typed your password correctly, you should by now be logged into DragonFly and ready to try out all the available commands. You should see the MOTD or message of the day followed by a command prompt (a `#`, `$`, or `%` character). This indicates you have successfully logged into DragonFly. ### Multiple Consoles Running UNIX commands in one console is fine, but DragonFly can run many programs at once. Having one console where commands can be typed would be a bit of a waste when an operating system like DragonFly can run dozens of programs at the same time. This is where virtual consoles can be very helpful. DragonFly can be configured to present you with many different virtual consoles. You can switch from one of them to any other virtual console by pressing a couple of keys on your keyboard. Each console has its own different output channel, and DragonFly takes care of properly redirecting keyboard input and monitor output as you switch from one virtual console to the next. Special key combinations have been reserved by DragonFly for switching consoles[(3)](#FTN.AEN1087). You can use **Alt** - **F1** , **Alt** - **F2** , through **Alt** - **F8** to switch to a different virtual console in DragonFly. As you are switching from one console to the next, DragonFly takes care of saving and restoring the screen output. The result is an illusion of having multiple virtual screens and keyboards that you can use to type commands for DragonFly to run. The programs that you launch on one virtual console do not stop running when that console is not visible. They continue running when you have switched to a different virtual console. ### The /etc/ttys File The default configuration of DragonFly will start up with eight virtual consoles. This is not a hardwired setting though, and you can easily customize your installation to boot with more or fewer virtual consoles. The number and settings of the virtual consoles are configured in the `/etc/ttys` file. You can use the `/etc/ttys` file to configure the virtual consoles of DragonFly. Each uncommented line in this file (lines that do not start with a `#` character) contains settings for a single terminal or virtual console. The default version of this file that ships with DragonFly configures nine virtual consoles, and enables eight of them. They are the lines that start with `ttyv`: # name getty type status comments # ttyv0 "/usr/libexec/getty Pc" cons25 on secure # Virtual terminals ttyv1 "/usr/libexec/getty Pc" cons25 on secure ttyv2 "/usr/libexec/getty Pc" cons25 on secure ttyv3 "/usr/libexec/getty Pc" cons25 on secure ttyv4 "/usr/libexec/getty Pc" cons25 on secure ttyv5 "/usr/libexec/getty Pc" cons25 on secure ttyv6 "/usr/libexec/getty Pc" cons25 on secure ttyv7 "/usr/libexec/getty Pc" cons25 on secure ttyv8 "/usr/local/bin/xdm -nodaemon" xterm off secure For a detailed description of every column in this file and all the options you can use to set things up for the virtual consoles, consult the [ttys(5)](http://leaf.dragonflybsd.org/cgi/web-man?command#ttys§ion5) manual page. ### Single User Mode Console A detailed description of what single user mode is can be found in [boot-init.html#BOOT-SINGLEUSER Section 7.5.2]. It is worth noting that there is only one console when you are running DragonFly in single user mode. There are no virtual consoles available. The settings of the single user mode console can also be found in the `/etc/ttys` file. Look for the line that starts with `console`: # name getty type status comments # # If console is marked "insecure", then init will ask for the root password # when going to single-user mode. console none unknown off secure **Note:** As the comments above the `console` line indicate, you can edit this line and change `secure` to `insecure`. If you do that, when DragonFly boots into single user mode, it will still ask for the `root` password. ***Be careful when changing this to insecure***. If you ever forget the `root` password, booting into single user mode is a bit involved. It is still possible, but it might be a bit hard for someone who is not very comfortable with the DragonFly booting process and the programs involved. #### Notes [[!table data=""" [ (1)](consoles.html#AEN1036) | This is what `i386` means. Note that even if you are not running DragonFly on an Intel 386 CPU, this is going to be `i386`. It is not the type of your processor, but the processor ***architecture*** that is shown here. [ (2)](consoles.html#AEN1060) | Startup scripts are programs that are run automatically by DragonFly when booting. Their main function is to set things up for everything else to run, and start any services that you have configured to run in the background doing useful things. [ (3)](consoles.html#AEN1087) | A fairly technical and accurate description of all the details of the DragonFly console and keyboard drivers can be found in the manual pages of [syscons(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=syscons§ion4), [atkbd(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=atkbd§ion=4), [vidcontrol(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=vidcontrol§ion=1) and [kbdcontrol(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kbdcontrol§ion=1). We will not expand on the details here, but the interested reader can always consult the manual pages for a more detailed and thorough explanation of how things work. | """]] ## Permissions DragonFly, being a direct descendant of BSD UNIX®, is based on several key UNIX concepts. The first and most pronounced is that DragonFly is a multi-user operating system. The system can handle several users all working simultaneously on completely unrelated tasks. The system is responsible for properly sharing and managing requests for hardware devices, peripherals, memory, and CPU time fairly to each user. Because the system is capable of supporting multiple users, everything the system manages has a set of permissions governing who can read, write, and execute the resource. These permissions are stored as three octets broken into three pieces, one for the owner of the file, one for the group that the file belongs to, and one for everyone else. This numerical representation works like this: [[!table data=""" | Value | Permission | Directory Listing 0 | No read, no write, no execute | `---` 1 | No read, no write, execute | `--x` 2 | No read, write, no execute | `-w-` 3 | No read, write, execute | `-wx` 4 | Read, no write, no execute | `r--` 5 | Read, no write, execute | `r-x` 6 | Read, write, no execute | `rw-` 7 | Read, write, execute | `rwx` | """]] You can use the `-l` command line argument to [ls(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ls§ion1) to view a long directory listing that includes a column with information about a file's permissions for the owner, group, and everyone else. For example, a `ls -l` in an arbitrary directory may show: % ls -l total 530 -rw-r--r-- 1 root wheel 512 Sep 5 12:31 myfile -rw-r--r-- 1 root wheel 512 Sep 5 12:31 otherfile -rw-r--r-- 1 root wheel 7680 Sep 5 12:31 email.txt ... Here is how the first column of `ls -l` is broken up: -rw-r--r-- The first (leftmost) character tells if this file is a regular file, a directory, a special character device, a socket, or any other special pseudo-file device. In this case, the `-` indicates a regular file. The next three characters, `rw-` in this example, give the permissions for the owner of the file. The next three characters, `r--`, give the permissions for the group that the file belongs to. The final three characters, `r--`, give the permissions for the rest of the world. A dash means that the permission is turned off. In the case of this file, the permissions are set so the owner can read and write to the file, the group can read the file, and the rest of the world can only read the file. According to the table above, the permissions for this file would be `644`, where each digit represents the three parts of the file's permission. This is all well and good, but how does the system control permissions on devices? DragonFly actually treats most hardware devices as a file that programs can open, read, and write data to just like any other file. These special device files are stored on the `/dev` directory. Directories are also treated as files. They have read, write, and execute permissions. The executable bit for a directory has a slightly different meaning than that of files. When a directory is marked executable, it means it can be traversed into, that is, it is possible to ***cd*** (change directory) into it. This also means that within the directory it is possible to access files whose names are known (subject, of course, to the permissions on the files themselves). In particular, in order to perform a directory listing, read permission must be set on the directory, whilst to delete a file that one knows the name of, it is necessary to have write ***and*** execute permissions to the directory containing the file. There are more permission bits, but they are primarily used in special circumstances such as setuid binaries and sticky directories. If you want more information on file permissions and how to set them, be sure to look at the [chmod(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chmod§ion1) manual page. ### Symbolic Permissions ***Contributed by Tom Rhodes.*** Symbolic permissions, sometimes referred to as symbolic expressions, use characters in place of octal values to assign permissions to files or directories. Symbolic expressions use the syntax of (who) (action) (permissions), where the following values are available: [[!table data=""" Option | Letter | Represents (who) | u | User (who) | g | Group owner (who) | o | Other (who) | a | All (***world***) (action) | + | Adding permissions (action) | - | Removing permissions (action) | = | Explicitly set permissions (permissions) | r | Read (permissions) | w | Write (permissions) | x | Execute (permissions) | t | Sticky bit (permissions) | s | Set UID or GID | """]] These values are used with the [chmod(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chmod&section1) command just like before, but with letters. For an example, you could use the following command to block other users from accessing `FILE`: % chmod go=FILE A comma separated list can be provided when more than one set of changes to a file must be made. For example the following command will remove the groups and ***world*** write permission on `FILE`, then it adds the execute permissions for everyone: % chmod go-w,a+x FILE ### DragonFly File Flags ***Contributed by Tom Rhodes.*** In addition to file permissions discussed previously, DragonFly supports the use of ***file flags.*** These flags add an additional level of security and control over files (but not directories), helping to ensure that in some cases not even `root` can remove or alter files. File flags are altered by using the [chflags(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chflags&section1) utility, using a simple interface. For example, to enable the system undeletable flag on the file `file1`, issue the following command: # chflags sunlink file1 To disable the system undeletable flag, simply issue the previous command with ***no*** in front of the `sunlink`. Observe: # chflags nosunlink file1 To view the flags of this file, use the [ls(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ls&section1) command with the `-lo` flags: # ls -lo file1 The output should look like the following: -rw-r--r-- 1 trhodes trhodes sunlnk 0 Mar 1 05:54 file1 Several flags may only added or removed to files by the `root` user. In other cases, the file owner may set these flags. It is recommended an administrator read over the [chflags(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chflags§ion1) and [chflags(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=chflags§ion=2) manual pages for more information. ## Directory Structure The DragonFly directory hierarchy is fundamental to obtaining an overall understanding of the system. The most important concept to grasp is that of the root directory, ***/***. This directory is the first one mounted at boot time and it contains the base system necessary to prepare the operating system for multi-user operation. The root directory also contains mount points for every other file system that you may want to mount. A mount point is a directory where additional file systems can be grafted onto the root file system. This is further described in [ this Section](disk-organization.html). Standard mount points include `/usr`, `/var`, `/tmp`, `/mnt`, and `/cdrom`. These directories are usually referenced to entries in the file `/etc/fstab`. `/etc/fstab` is a table of various file systems and mount points for reference by the system. Most of the file systems in `/etc/fstab` are mounted automatically at boot time from the script [rc(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rc§ion8) unless they contain the `noauto` option. Details can be found in [ this section](mount-unmount.html#DISKS-FSTAB). A complete description of the file system hierarchy is available in [hier(7)](http://leaf.dragonflybsd.org/cgi/web-man?command=hier§ion7). For now, a brief overview of the most common directories will suffice. [[!table data=""" Directory | Description `/` | Root directory of the file system. `/bin/` | User utilities fundamental to both single-user and multi-user environments. `/boot/` | Programs and configuration files used during operating system bootstrap. `/boot/defaults/` | Default bootstrapping configuration files; see [loader.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=loader.conf§ion5). `/dev/` | Device nodes; see [intro(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=intro§ion4). `/etc/` | System configuration files and scripts. `/etc/defaults/` | Default system configuration files; see [rc(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rc§ion8). `/etc/mail/` | Configuration files for mail transport agents such as [sendmail(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=sendmail§ion8). `/etc/namedb/` | `named` configuration files; see [named(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=named§ion8). `/etc/periodic/` | Scripts that are run daily, weekly, and monthly, via [cron(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=cron§ion8); see [periodic(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=periodic§ion=8). `/etc/ppp/` | `ppp` configuration files; see [ppp(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=ppp§ion8). `/mnt/` | Empty directory commonly used by system administrators as a temporary mount point. `/proc/` | Process file system; see [procfs(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=procfs§ion5), [mount_procfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount_procfs§ion=8). `/root/` | Home directory for the `root` account. `/sbin/` | System programs and administration utilities fundamental to both single-user and multi-user environments. `/tmp/` | Temporary files. The contents of `/tmp` are usually NOT preserved across a system reboot. A memory-based file system is often mounted at `/tmp`. This can be automated with an entry in `/etc/fstab`; see [mfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mfs§ion8). `/usr/` | The majority of user utilities and applications. `/usr/bin/` | Common utilities, programming tools, and applications. `/usr/dports/` | The dports tree for installing packages (optional). `/usr/include/` | Standard C include files. `/usr/lib/` | Archive libraries. `/usr/libdata/` | Miscellaneous utility data files. `/usr/libexec/` | System daemons & system utilities (executed by other programs). `/usr/local/` | Local executables, libraries, etc. Within `/usr/local`, the general layout sketched out by [hier(7)](http://leaf.dragonflybsd.org/cgi/web-man?command=hier§ion7) for `/usr` should be used. An exceptions is the man directory, which is directly under `/usr/local` rather than under `/usr/local/share`. dports uses `/usr/local`. `/usr/obj/` | Architecture-specific target tree produced by building the `/usr/src` tree. `/usr/sbin/` | System daemons & system utilities (executed by users). `/usr/share/` | Architecture-independent files. `/usr/src/` | BSD and/or local source files. `/var/` | Multi-purpose log, temporary, transient, and spool files. A memory-based file system is sometimes mounted at `/var`. This can be automated with an entry in `/etc/fstab`; see [mfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mfs§ion8). `/var/log/` | Miscellaneous system log files. `/var/mail/` | User mailbox files. `/var/spool/` | Miscellaneous printer and mail system spooling directories. `/var/tmp/` | Temporary files. The files are usually preserved across a system reboot, unless `/var` is a memory-based file system. `/var/yp` | NIS maps. | """]] ## Disk Organization The smallest unit of organization that DragonFly uses to find files is the filename. Filenames are case-sensitive, which means that `readme.txt` and `README.TXT` are two separate files. DragonFly does not use the extension (`.txt`) of a file to determine whether the file is a program, or a document, or some other form of data. Files are stored in directories. A directory may contain no files, or it may contain many hundreds of files. A directory can also contain other directories, allowing you to build up a hierarchy of directories within one another. This makes it much easier to organize your data. Files and directories are referenced by giving the file or directory name, followed by a forward slash, `/`, followed by any other directory names that are necessary. If you have directory `foo`, which contains directory `bar`, which contains the file `readme.txt`, then the full name, or ***path*** to the file is `foo/bar/readme.txt`. Directories and files are stored in a file system. Each file system contains exactly one directory at the very top level, called the ***root directory*** for that file system. This root directory can then contain other directories. So far this is probably similar to any other operating system you may have used. There are a few differences; for example, MS-DOS® and Windows® use `\`. DragonFly does not use drive letters, or other drive names in the path. You would not write `c:/foo/bar/readme.txt` on DragonFly. Instead, one file system is designated the ***root file system***. The root file system's root directory is referred to as `/`. Every other file system is then ***mounted*** under the root file system. No matter how many disks you have on your DragonFly system, every directory appears to be part of the same disk. Suppose you have three file systems, called `A`, `B`, and `C`. Each file system has one root directory, which contains two other directories, called `A1`, `A2` (and likewise `B1`, `B2` and `C1`, `C2`). Call `A` the root file system. If you used the `ls` command to view the contents of this directory you would see two subdirectories, `A1` and `A2`. The directory tree looks like this: A file system must be mounted on to a directory in another file system. So now suppose that you mount file system `B` on to the directory `A1`. The root directory of `B` replaces `A1`, and the directories in `B` appear accordingly: Any files that are in the `B1` or `B2` directories can be reached with the path `/A1/B1` or `/A1/B2` as necessary. Any files that were in `/A1` have been temporarily hidden. They will reappear if `B` is ***unmounted*** from A. If `B` had been mounted on `A2` then the diagram would look like this: and the paths would be `/A2/B1` and `/A2/B2` respectively. File systems can be mounted on top of one another. Continuing the last example, the `C` file system could be mounted on top of the `B1` directory in the `B` file system, leading to this arrangement: Or `C` could be mounted directly on to the `A` file system, under the `A1` directory: If you are familiar with MS-DOS, this is similar, although not identical, to the `join` command. ### The fstab File During the [boot process](boot.html), file systems listed in `/etc/fstab` are automatically mounted (unless they are listed with the `noauto` option). The `/etc/fstab` file contains a list of lines of the following format: device mount-point fstype options dumpfreq passno These parameters have the following meaning: * `device`: A device name (which should exist), as explained [here](disks-naming.html). * `mount-point`: A directory (which should exist), on which to mount the file system. * `fstype`: The file system type to pass to [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount§ion8). The default DragonFly file system is `ufs`. * `options`: Either `rw` for read-write file systems, or `ro` for read-only file systems, followed by any other options that may be needed. A common option is `noauto` for file systems not normally mounted during the boot sequence. Other options are listed in the [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount§ion8) manual page. * `dumpfreq`: This is used by [dump(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=dump§ion8) to determine which file systems require dumping. If the field is missing, a value of zero is assumed. * `passno`: This determines the order in which file systems should be checked. File systems that should be skipped should have their `passno` set to zero. The root file system (which needs to be checked before everything else) should have its `passno` set to one, and other file systems' `passno` should be set to values greater than one. If more than one file systems have the same `passno` then [fsck(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fsck§ion8) will attempt to check file systems in parallel if possible. Consult the [fstab(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=fstab§ion5) manual page for more information on the format of the `/etc/fstab` file and the options it contains. ### The mount Command The [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount§ion8) command is what is ultimately used to mount file systems. In its most basic form, you use: # mount device mountpoint Or, if `mountpoint` is specified in `/etc/fstab`, just: # mount mountpoint There are plenty of options, as mentioned in the [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount§ion8) manual page, but the most common are: **Mount Options** * `-a`: Mount all the file systems listed in `/etc/fstab`. Except those marked as `noauto`, excluded by the `-t` flag, or those that are already mounted. * `-d`: Do everything except for the actual mount system call. This option is useful in conjunction with the `-v` flag to determine what [mount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=mount§ion8) is actually trying to do. * `-f`: Force the mount of an unclean file system (dangerous), or forces the revocation of write access when downgrading a file system's mount status from read-write to read-only. * `-r`: Mount the file system read-only. This is identical to using the `rdonly` argument to the `-o` option. * `-t` ***fstype***: Mount the given file system as the given file system type, or, if used with `-a` option, mount only file systems of the given type. `ufs` is the default file system type. * `-u`: Update mount options on the file system. * `-v`: Be verbose. * `-w`: Mount the file system read-write. The `-o` option takes a comma-separated list of the options, including the following: * `nodev:` Do not interpret special devices on the file system. This is a useful security option. * `noexec`: Do not allow execution of binaries on this file system. This is also a useful security option. * `nosuid`: Do not interpret setuid or setgid flags on the file system. This is also a useful security option. ### The umount Command The [umount(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=umount§ion8) command takes, as a parameter, one of a mountpoint, a device name, or the `-a` or `-A` option. All forms take `-f` to force unmounting, and `-v` for verbosity. Be warned that `-f` is not generally a good idea. Forcibly unmounting file systems might crash the computer or damage data on the file system. `-a` and `-A` are used to unmount all mounted file systems, possibly modified by the file system types listed after `-t`. `-A`, however, does not attempt to unmount the root file system. ## Choosing File System Layout This is not normally something you need to concern yourself with. Typically you create file systems when installing DragonFly and decide where to mount them, and then never change them unless you add a new disk. It is entirely possible to have one large root file system, and not need to create any others. There are some drawbacks to this approach, and one advantage. **Benefits of Multiple File Systems** * Different file systems can have different ***mount options***. For example, with careful planning, the root file system can be mounted read-only, making it impossible for you to inadvertently delete or edit a critical file. Separating user-writable file systems, such as `/home`, from other file systems also allows them to be mounted ***nosuid***; this option prevents the ***suid***/***guid*** bits on executables stored on the file system from taking effect, possibly improving security. * The UFS file system automatically optimizes the layout of files, depending on how the file system is being used. So a file system that contains many small files that are written frequently will have a different optimization to one that contains fewer, larger files. By having one big file system this optimization breaks down. * DragonFly's file systems are very robust should you lose power. However, a power loss at a critical point could still damage the structure of the file system. By splitting your data over multiple file systems it is more likely that the system will still come up, making it easier for you to restore from backup as necessary. This a major reason to make the root file system of limited size, and with low write activity. **Benefit of a Single File System** * File systems are a fixed size. If you create a file system when you install DragonFly and give it a specific size, you may later discover that you need to make the partition bigger. The [growfs(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=growfs&section8) command makes it possible to increase the size of a UFS file system on the fly. ## Disk Slices, Partitions and local UNIX file systems *** Heavily edited by Nick Matavka*** DragonFly BSD divides disks into partitions and slices; it refers to locations on a disk by means of their unique codes. For instance, the disk code `ad1s3d` has a clear meaning: IDE hard disk one, slice three, root file system. Meanings for other such codes will become apparent by the end of this section; first of all come the meanings for the physical drive codes. The most common are: [[!table data=""" Code | Meaning `ad` | ATAPI (IDE) disk `da` | SCSI direct access disk `acd` | ATAPI (IDE) CDROM `cd` | SCSI CDROM `vn` | Virtual disk `fd` | Floppy disk | """]] ### Slices In BSD UNIX, including DragonFly, what are elsewhere known as ***partitions*** are instead known as ***slices***; on a multi-boot system, every operating system occupies at least one slice and is aware of the others. Linux, and most UNIX operating systems, generally occupy at least two slices, one for the file system and one for swap space; on the other hand, BSD (with the exception of MacOS/DarwinBSD) may occupy only one slice, using an alternative method (called ***partitioning*** in BSD) to segregate file system and swap space. Programs such as `parted` and `gparted`, contrary to their names, are in fact disk slicers. In DragonFly, disk slices are designated with the letter `s` for ***slice*** and a positive integer, beginning either from zero or one, depending on the slicing scheme. The first slice of a physical disk is thus named `s0`; the second, `s1`; and so on. There can only be four ***physical*** slices on a disk, but one of these, designated the ***extended*** slice, may itself be sliced into ***logical*** slices. If an extended slice exists, the logical slices it contains are numbered beginning with `s5`. For instance, the disk `ad6` may be divided into physical slices `ad6s1`, `ad6s2` (the extended slice, containing logical slices `ad6s5` and `ad6s6`), and `ad6s3`. Note that if there are less than four physical slices, the relevant numbers are skipped, even if there are logical slices. DragonFly support two schemes for slices, MBR and GPT. Either of them can manage all of the slices on a disk: * MBR: are set up using [fdisk(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fdisk&section8) and can be up to two terabytes (2,048 GB) in size. Usually, MBR slices are numbered from 1; if there is only one slice on the disk (that is, the disk is ***dangerously dedicated***), however,it has slice number 0. * GPT: are set up using [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&section8) and support disk sizes up to eight exabytes (eight billion terabytes, a ludicrously large and, within the foreseeable future, entirely theoretical size equivalent to 800,000 times the sum total of printed works within the Library of Congress). ***Dangerous dedication*** is irrelevant in GPT; slices are ***always*** numbered from 0. ***NOTE:*** DragonFly doesn't support booting from a GPT slice in DragonFly 2.0. DragonFly 2.1 does have some support for booting from a GPT slice, this is described in [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&section=8). ### Partitions Uniquely in BSD, disk slices contain `disklabel` partitions, not to be confused with the word partition in its usual meaning (that kind of partition is called a slice in BSD). In most variants of UNIX, at least two slices are used to contain the system: one for the primary file system, and one for swap space. With one exception, BSD can dispense with slices entirely and use a utility known as `disklabel` (or `bsdlabel`) to ***partition*** the disk instead. All BSD UNIX operating systems support eight partitions per slice, labelled `a` through `h`; most BSD systems, DragonFly included, support an additional eight, labelled `i` through `p`, for a total of sixteen per slice. Partition layout is defined in a label on the slice where they reside. Since each partition may have its own ***file system***, ***in BSD***, one slice may be formatted in several different file systems (a situation that does not hold true in Linux or Windows). Partition layout is defined in a label on the slice where the partition reside. DragonFly support two types of disk labels, disklabel32 and disklabel64 (the default): * [disklabel32(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel&section8): 32 bit disk label which can use slices with size up to 2 TB. * [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&section8): 64 bit disk label which can use very large slices: size up to 16 million TB. ***By convention***, four partition labels are reserved by the system and have special meanings. The convention does not strictly have to hold true, but it is highly recommended to follow this gentleman's agreement: [[!table data=""" Partition | Convention `a` | Normally contains the root file system `b` | Normally contains swap space `c` | Normally the same size as the enclosing slice. This allows utilities that need to work on the entire slice (for example, a bad block scanner) to work on the `c` partition. You would not normally create a file system on this partition. This is not necessarily true; it is possible to use the 'c' partition as a normal partition. `d` | Normally the same size as the entire physical disk. This is now rare, but to this day, some tools may operate oddly if told to work on partition `d`. | """]] ### Local UNIX file systems Each partition can contain only one ***file system***. Therefore, file systems often are described by either their typical mount point in the file system hierarchy, or the letter of the `disklabel` partition they are contained in. DragonFly BSD supports two local UNIX file systems, UFS and HAMMER: * UFS: is the classic BSD UNIX file system (see [ffs(5)](http://leaf.dragonflybsd.org/cgi/web-man?command#ffs&section5)). It supports a volume size up to two terabytes. * [HAMMER(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=HAMMER&section5): introduced in DragonFly 2.0, this is a new file system with many advanced features. HAMMERfs supports a volume size of up to one exabyte (one million terabytes). ***Historically***, the desirability of HAMMERfs increased with storage capacity. For booting DragonFly from a small, local file system, UFS was previously recommended, with the option of a BOOT+HAMMER set up (512 MB UFS boot partition, the rest HAMMERfs). For moderate storage requirements, UFS continued to be an option, but the extra features boasted by HAMMERfs (such as history retention) made it more desirable in this regard. Then, as now, HAMMERfs was the unrivalled king of the large partition, usually with a [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&section8) label on a GPT slice. As of DragonFly version 3.6, this question is mostly, or entirely, of academic interest. HAMMERfs is now recommended for all volumes greater than eighty gigabytes---that is to say, all volumes manufactured within the last five years, and a goodly portion of older ones as well. ## The HAMMER File System [HAMMER(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=HAMMER&section5) is a rather new file system, under active development. HAMMERfs reached beta in release 2.0. As of release 2.2.1, HAMMERfs is considered to be appropriate for use in the production environment; DragonFly is currently in release 3.6. If you are deploying DragonFly on a low-capacity, low-memory system, you should evaluate if HAMMERfs is suitable for your needs; for a personal computer or server of even medium vintage, no thought need go into this, as it will be found that HAMMERfs is the file system ***of choice***. [HAMMER(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=HAMMER&section5) has several advanced features not found in UFS: * Large file systems: HAMMERfs supports systems up to one exabyte (that is, one million terabytes) in size. * Multiple volumes: A HAMMER file system can span up to 256 disks. Each part of a HAMMER file system is called a volume; each volume can be up to 4096 TB in size. * Re-sizeability: As of release 2.4, the `expand` directive to [hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&section=8) allows HAMMER file systems to be easily re-sized; volumes may also be added and removed. * Instant crash recovery: Should a crash occur, HAMMER obviates the necessity for `fsck`, saving precious time in mission-critical applications. * Mirroring: HAMMERfs makes it possible to ***mirror*** a master file system to a number of slave file systems. Although mirror targets are, by necessity, read-only, they do have history available. The history retention policy can even be different on slaves and master. Mirroring over network is supported, and unreliable connections are handled gracefully. * Data integrity: HAMMERfs makes data integrity a priority by implementing cyclic redundancy checks on all data. If bits become corrupted, this will be detected. All these features are subordinate to the single, basic, overarching purpose of the HAMMER file system: ***full history retention***. With HAMMERfs, **all** file system changes are saved every ~30 seconds. Changes are written at least when sync() is called (see [syncer(4)](http://leaf.dragonflybsd.org/cgi/web-man?command=syncer&section4)). Every time data are written to disk, a transaction is completed, this is assigned an identifier, and the file updated can after this be accessed with the contents from this moment. To access the file as it was then, all the user must do is add the transaction identifier to the file name, in the form `file@@`. The TID can be saved from the `snapshot`, `cleanup`, or `synctid` [hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&section=8) command, or looked up with the `hammer history file` command. This history will typically grow over time, so any disk will fill up over time. Two things are done so the disk does not fill up too fast, or too much. First of all, at least moderately large disks are used. Second, HAMMER can be made self-managing with a policy for which history to save for how long. For example, make a snapshot every hour and `prune` and `reblock` ([hammer(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=hammer&section=8)) regularly. When snapshots get older than one month, keep them for six hours; when older than three months, keep them for a day; when older than three years, keep them for a month. Historically, you needed to set up [cron(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=cron&section8) jobs for this yourself, but HAMMER now includes a utility to make this easy. ### Adding a Disk Adding a disk is done by installing it physically and by connecting it to a disk controller supported by DragonFly BSD. If you are in doubt as to whether a particular disk controller is supported, the manual pages for disk controllers can be consulted (`man -k disk` or `man -k scsi` can be of help). Another, easier way of ascertaining support for a controller is to boot with the controller installed, and note if the boot messages contain the controller. Assuming that disk `ad6` is installed, we could set it up the old-fashioned way, using [fdisk(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=fdisk&section8) and disklabel(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel&section8) or the modern way, with [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&section8) and [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&section8), or any combination thereof. In this example, we chose [gpt(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=gpt&section=8) and [disklabel64(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=disklabel64&section=8). # gpt -v create ad6 [...] # gpt add -s1 ad6 ad6s0 # gpt add ad6 ad6s1 # gpt show ad6 [...] In the above example, we first create the GPT and then add two slices. The first slice added is `ad6s0`, which is made a dummy slice of size 1 sector. The reason for this is backwards compatibility: veteran users may remember that `s0` has special meaning in MBR slice schemes, but this is not true in GPT slices. The second slice, `ad6s1`, will cover the rest of the disk: # disklabel64 -rw ad6s1 auto # disklabel64 -e ad6s1 # edit label to add partitions as needed ## Processes DragonFly is a multi-tasking operating system. This means that it seems as though more than one program is running at once. Each program running at any one time is called a ***process***. Every command you run will start at least one new process, and there are a number of system processes that run all the time, keeping the system functional. Each process is uniquely identified by a number called a ***process ID***, or ***PID***, and, like files, each process also has one owner and group. The owner and group information is used to determine what files and devices the process can open, using the file permissions discussed earlier. Most processes also have a parent process. The parent process is the process that started them. For example, if you are typing commands to the shell then the shell is a process, and any commands you run are also processes. Each process you run in this way will have your shell as its parent process. The exception to this is a special process called [init(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=init§ion8). `init` is always the first process, so its PID is always 1. `init` is started automatically by the kernel when DragonFly starts. Two commands are particularly useful to see the processes on the system, [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps§ion1) and [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top§ion=1). The `ps` command is used to show a static list of the currently running processes, and can show their PID, how much memory they are using, the command line they were started with, and so on. The `top` command displays all the running processes, and updates the display every few seconds, so that you can interactively see what your computer is doing. By default, `ps` only shows you the commands that are running and are owned by you. For example: % ps PID TT STAT TIME COMMAND 298 p0 Ss 0:01.10 tcsh 7078 p0 S 2:40.88 xemacs mdoc.xsl (xemacs-21.1.14) 37393 p0 I 0:03.11 xemacs freebsd.dsl (xemacs-21.1.14) 48630 p0 S 2:50.89 /usr/local/lib/netscape-linux/navigator-linux-4.77.bi 48730 p0 IW 0:00.00 (dns helper) (navigator-linux-) 72210 p0 R+ 0:00.00 ps 390 p1 Is 0:01.14 tcsh 7059 p2 Is+ 1:36.18 /usr/local/bin/mutt -y 6688 p3 IWs 0:00.00 tcsh 10735 p4 IWs 0:00.00 tcsh 20256 p5 IWs 0:00.00 tcsh 262 v0 IWs 0:00.00 -tcsh (tcsh) 270 v0 IW+ 0:00.00 /bin/sh /usr/X11R6/bin/startx -- -bpp 16 280 v0 IW+ 0:00.00 xinit /home/nik/.xinitrc -- -bpp 16 284 v0 IW 0:00.00 /bin/sh /home/nik/.xinitrc 285 v0 S 0:38.45 /usr/X11R6/bin/sawfish As you can see in this example, the output from [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps§ion1) is organized into a number of columns. `PID` is the process ID discussed earlier. PIDs are assigned starting from 1, go up to 99999, and wrap around back to the beginning when you run out. The `TT` column shows the tty the program is running on, and can safely be ignored for the moment. `STAT` shows the program's state, and again, can be safely ignored. `TIME` is the amount of time the program has been running on the CPU--this is usually not the elapsed time since you started the program, as most programs spend a lot of time waiting for things to happen before they need to spend time on the CPU. Finally, `COMMAND` is the command line that was used to run the program. [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ps§ion1) supports a number of different options to change the information that is displayed. One of the most useful sets is `auxww`. `a` displays information about all the running processes, not just your own. `u` displays the username of the process' owner, as well as memory usage. `x` displays information about daemon processes, and `ww` causes [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps§ion=1) to display the full command line, rather than truncating it once it gets too long to fit on the screen. The output from [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top§ion1) is similar. A sample session looks like this: % top last pid: 72257; load averages: 0.13, 0.09, 0.03 up 0+13:38:33 22:39:10 47 processes: 1 running, 46 sleeping CPU states: 12.6% user, 0.0% nice, 7.8% system, 0.0% interrupt, 79.7% idle Mem: 36M Active, 5256K Inact, 13M Wired, 6312K Cache, 15M Buf, 408K Free Swap: 256M Total, 38M Used, 217M Free, 15% Inuse PID USERNAME PRI NICE SIZE RES STATE TIME WCPU CPU COMMAND 72257 nik 28 0 1960K 1044K RUN 0:00 14.86% 1.42% top 7078 nik 2 0 15280K 10960K select 2:54 0.88% 0.88% xemacs-21.1.14 281 nik 2 0 18636K 7112K select 5:36 0.73% 0.73% XF86_SVGA 296 nik 2 0 3240K 1644K select 0:12 0.05% 0.05% xterm 48630 nik 2 0 29816K 9148K select 3:18 0.00% 0.00% navigator-linu 175 root 2 0 924K 252K select 1:41 0.00% 0.00% syslogd 7059 nik 2 0 7260K 4644K poll 1:38 0.00% 0.00% mutt ... The output is split into two sections. The header (the first five lines) shows the PID of the last process to run, the system load averages (which are a measure of how busy the system is), the system uptime (time since the last reboot) and the current time. The other figures in the header relate to how many processes are running (47 in this case), how much memory and swap space has been taken up, and how much time the system is spending in different CPU states. Below that are a series of columns containing similar information to the output from [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps§ion1). As before you can see the PID, the username, the amount of CPU time taken, and the command that was run. [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top§ion=1) also defaults to showing you the amount of memory space taken by the process. This is split into two columns, one for total size, and one for resident size--total size is how much memory the application has needed, and the resident size is how much it is actually using at the moment. In this example you can see that **Netscape®** has required almost 30 MB of RAM, but is currently only using 9 MB. [top(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=top§ion1) automatically updates this display every two seconds; this can be changed with the `s` option. ## Daemons, Signals, and Killing Processes When you run an editor it is easy to control the editor, tell it to load files, and so on. You can do this because the editor provides facilities to do so, and because the editor is attached to a ***terminal***. Some programs are not designed to be run with continuous user input, and so they disconnect from the terminal at the first opportunity. For example, a web server spends all day responding to web requests, it normally does not need any input from you. Programs that transport email from site to site are another example of this class of application. We call these programs ***daemons***. Daemons were characters in Greek mythology; neither good or evil, they were little attendant spirits that, by and large, did useful things for mankind. Much like the web servers and mail servers of today do useful things. This is why the mascot for a number of BSD-based operating systems has, for a long time, been a cheerful looking daemon with sneakers and a pitchfork. There is a convention to name programs that normally run as daemons with a trailing ***d***. **BIND** is the Berkeley Internet Name Daemon (and the actual program that executes is called `named`), the **Apache** web server program is called `httpd`, the line printer spooling daemon is `lpd` and so on. This is a convention, not a hard and fast rule; for example, the main mail daemon for the **Sendmail** application is called `sendmail`, and not `maild`, as you might imagine. Sometimes you will need to communicate with a daemon process. These communications are called ***signals***, and you can communicate with a daemon (or with any other running process) by sending it a signal. There are a number of different signals that you can send--some of them have a specific meaning, others are interpreted by the application, and the application's documentation will tell you how that application interprets signals. You can only send a signal to a process that you own. If you send a signal to someone else's process with [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill§ion=1) or [kill(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill§ion=2) permission will be denied. The exception to this is the `root` user, who can send signals to everyone's processes. DragonFly will also send applications signals in some cases. If an application is badly written, and tries to access memory that it is not supposed to, DragonFly sends the process the ***Segmentation Violation*** signal (`SIGSEGV`). If an application has used the [alarm(3)](http://leaf.dragonflybsd.org/cgi/web-man?command=alarm§ion=3) system call to be alerted after a period of time has elapsed then it will be sent the Alarm signal (`SIGALRM`), and so on. Two signals can be used to stop a process, `SIGTERM` and `SIGKILL`. `SIGTERM` is the polite way to kill a process; the process can ***catch*** the signal, realize that you want it to shut down, close any log files it may have open, and generally finish whatever it is doing at the time before shutting down. In some cases a process may even ignore `SIGTERM` if it is in the middle of some task that can not be interrupted. `SIGKILL` can not be ignored by a process. This is the ***I do not care what you are doing, stop right now*** signal. If you send `SIGKILL` to a process then DragonFly will stop that process there and then[(1)](#FTN.AEN2181). The other signals you might want to use are `SIGHUP`, `SIGUSR1`, and `SIGUSR2`. These are general purpose signals, and different applications will do different things when they are sent. Suppose that you have changed your web server's configuration file--you would like to tell the web server to re-read its configuration. You could stop and restart `httpd`, but this would result in a brief outage period on your web server, which may be undesirable. Most daemons are written to respond to the `SIGHUP` signal by re-reading their configuration file. So instead of killing and restarting `httpd` you would send it the `SIGHUP` signal. Because there is no standard way to respond to these signals, different daemons will have different behavior, so be sure and read the documentation for the daemon in question. Signals are sent using the [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill§ion=1) command, as this example shows. **Sending a Signal to a Process** This example shows how to send a signal to [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd§ion=8). The `inetd` configuration file is `/etc/inetd.conf`, and `inetd` will re-read this configuration file when it is sent `SIGHUP`. 1. Find the process ID of the process you want to send the signal to. Do this using [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command#ps§ion=1) and [grep(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=grep§ion=1). The [grep(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=grep§ion=1) command is used to search through output, looking for the string you specify. This command is run as a normal user, and [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd§ion=8) is run as `root`, so the `ax` options must be given to [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps§ion=1). % ps -ax | grep inetd 198 ?? IWs 0:00.00 inetd -wW So the [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#inetd§ion8) PID is 198. In some cases the `grep inetd` command might also occur in this output. This is because of the way [ps(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=ps§ion=1) has to find the list of running processes. 2. Use [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill§ion=1) to send the signal. Because [inetd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=inetd§ion=8) is being run by `root` you must use [su(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=su§ion=1) to become `root` first. % su Password: # /bin/kill -s HUP 198 In common with most UNIX® commands, [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill§ion=1) will not print any output if it is successful. If you send a signal to a process that you do not own then you will see `kill: PID: Operation not permitted`. If you mistype the PID you will either send the signal to the wrong process, which could be bad, or, if you are lucky, you will have sent the signal to a PID that is not currently in use, and you will see `kill: PID: No such process`. **Why Use `/bin/kill`?** Many shells provide the `kill` command as a built in command; that is, the shell will send the signal directly, rather than running `/bin/kill`. This can be very useful, but different shells have a different syntax for specifying the name of the signal to send. Rather than try to learn all of them, it can be simpler just to use the `/bin/kill ...` command directly. Sending other signals is very similar, just substitute `TERM` or `KILL` in the command line as necessary. **Important:** Killing random process on the system can be a bad idea. In particular, [init(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=init§ion=8), process ID 1, is very special. Running `/bin/kill -s KILL 1` is a quick way to shutdown your system. ***Always*** double check the arguments you run [kill(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=kill§ion=1) with ***before*** you press **Return** . ## Shells In DragonFly, a lot of everyday work is done in a command line interface called a shell. A shell's main job is to take commands from the input channel and execute them. A lot of shells also have built in functions to help everyday tasks such as file management, file globbing, command line editing, command macros, and environment variables. DragonFly comes with a set of shells, such as `sh`, the Bourne Shell, and `tcsh`, the improved C-shell. Many other shells are available from dports, such as `zsh` and `bash`. Which shell do you use? It is really a matter of taste. If you are a C programmer you might feel more comfortable with a C-like shell such as `tcsh`. If you have come from Linux or are new to a UNIX® command line interface you might try `bash`. The point is that each shell has unique properties that may or may not work with your preferred working environment, and that you have a choice of what shell to use. One common feature in a shell is filename completion. Given the typing of the first few letters of a command or filename, you can usually have the shell automatically complete the rest of the command or filename by hitting the **Tab** key on the keyboard. Here is an example. Suppose you have two files called `foobar` and `foo.bar`. You want to delete `foo.bar`. So what you would type on the keyboard is: `rm fo[ **Tab** ].[ **Tab** ]`. The shell would print out `rm foo[BEEP].bar`. The [BEEP] is the console bell, which is the shell telling me it was unable to totally complete the filename because there is more than one match. Both `foobar` and `foo.bar` start with `fo`, but it was able to complete to `foo`. If you type in `.`, then hit **Tab** again, the shell would be able to fill in the rest of the filename for you. Another feature of the shell is the use of environment variables. Environment variables are a variable key pair stored in the shell's environment space. This space can be read by any program invoked by the shell, and thus contains a lot of program configuration. Here is a list of common environment variables and what they mean: [[!table data=""" Variable | Description `USER` | Current logged in user's name. `PATH` | Colon separated list of directories to search for binaries. `DISPLAY` | Network name of the X11 display to connect to, if available. `SHELL` | The current shell. `TERM` | The name of the user's terminal. Used to determine the capabilities of the terminal. `TERMCAP` | Database entry of the terminal escape codes to perform various terminal functions. `OSTYPE` | Type of operating system. e.g., DragonFly. `MACHTYPE` | The CPU architecture that the system is running on. `EDITOR` | The user's preferred text editor. `PAGER` | The user's preferred text pager. `MANPATH` | Colon separated list of directories to search for manual pages. | """]] Setting an environment variable differs somewhat from shell to shell. For example, in the C-Style shells such as `tcsh` and `csh`, you would use `setenv` to set environment variables. Under Bourne shells such as `sh` and `bash`, you would use `export` to set your current environment variables. For example, to set or modify the `EDITOR` environment variable, under `csh` or `tcsh` a command like this would set `EDITOR` to `/usr/local/bin/emacs`: % setenv EDITOR /usr/local/bin/emacs Under Bourne shells: % export EDITOR="/usr/local/bin/emacs" You can also make most shells expand the environment variable by placing a `$` character in front of it on the command line. For example, `echo $TERM` would print out whatever `$TERM` is set to, because the shell expands `$TERM` and passes it on to `echo`. Shells treat a lot of special characters, called meta-characters as special representations of data. The most common one is the `*` character, which represents any number of characters in a filename. These special meta-characters can be used to do filename globbing. For example, typing in `echo *` is almost the same as typing in `ls` because the shell takes all the files that match `*` and puts them on the command line for `echo` to see. To prevent the shell from interpreting these special characters, they can be escaped from the shell by putting a backslash (`\`) character in front of them. `echo $TERM` prints whatever your terminal is set to. `echo \$TERM` prints `$TERM` as is. ### Changing Your Shell The easiest way to change your shell is to use the `chsh` command. Running `chsh` will place you into the editor that is in your `EDITOR` environment variable; if it is not set, you will be placed in `vi`. Change the ***Shell:*** line accordingly. You can also give `chsh` the `-s` option; this will set your shell for you, without requiring you to enter an editor. For example, if you wanted to change your shell to `bash`, the following should do the trick: % chsh -s /usr/local/bin/bash **Note:** The shell that you wish to use ***must*** be present in the `/etc/shells` file. If you have installed a shell from dports, then this should have been done for you already. If you installed the shell by hand, you must do this. For example, if you installed `bash` by hand and placed it into `/usr/opt/bin`, you would want to: # echo "/usr/opt/bin/bash" >> /etc/shells Then rerun `chsh`. ## Text Editors A lot of configuration in DragonFly is done by editing text files. Because of this, it would be a good idea to become familiar with a text editor. DragonFly comes with a few as part of the base system, and many more are available in the dports tree. The easiest and simplest editor to learn is an editor called **ee** , which stands for easy editor. To start **ee** , one would type at the command line `ee filename` where `filename` is the name of the file to be edited. For example, to edit `/etc/rc.conf`, type in `ee /etc/rc.conf`. Once inside of `ee`, all of the commands for manipulating the editor's functions are listed at the top of the display. The caret `^` character represents the **Ctrl** key on the keyboard, so `^e` expands to the key combination **Ctrl** + **e** . To leave **ee** , hit the **Esc** key, then choose leave editor. The editor will prompt you to save any changes if the file has been modified. DragonFly also comes with more powerful text editors such as **vi** as part of the base system, while other editors, like **emacs** and **vim** , are part of the dports tree. These editors offer much more functionality and power at the expense of being a little more complicated to learn. However if you plan on doing a lot of text editing, learning a more powerful editor such as **vim** or **emacs** will save you much more time in the long run. ## Devices and Device Nodes A device is a term used mostly for hardware-related activities in a system, including disks, printers, graphics cards, and keyboards. When DragonFly boots, the majority of what DragonFly displays are devices being detected. You can look through the boot messages again by viewing `/var/run/dmesg.boot`. For example, `acd0` is the first IDE CDROM drive, while `kbd0` represents the keyboard. Most of these devices in a UNIX® operating system must be accessed through special files called device nodes, which are located in the `/dev` directory. The device nodes in the `/dev` directory are created and destroyed automatically on DragonFly >= 2.4, by means of the device file system (devfs). ## Binary Formats To understand why DragonFly uses the [elf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=elf&section=5) format, you must first know a little about the three currently ***dominant*** executable formats for UNIX®: * [a.out(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=a.out&section=5) The oldest and ***classic*** UNIX object format. It uses a short and compact header with a magic number at the beginning that is often used to characterize the format (see [a.out(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=a.out&section=5) for more details). It contains three loaded segments: .text, .data, and .bss plus a symbol table and a string table. * COFF The SVR3 object format. The header now comprises a section table, so you can have more than just .text, .data, and .bss sections. * [elf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=elf&section=5) The successor to COFF, featuring multiple sections and 32-bit or 64-bit possible values. One major drawback: ELF was also designed with the assumption that there would be only one ABI per system architecture. That assumption is actually quite incorrect, and not even in the commercial SYSV world (which has at least three ABIs: SVR4, Solaris, SCO) does it hold true. DragonFly tries to work around this problem somewhat by providing a utility for ***branding*** a known ELF executable with information about the ABI it is compliant with. See the manual page for [brandelf(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=brandelf&section=1) for more information. DragonFly runs ELF. So, why are there so many different formats? Back in the dim, dark past, there was simple hardware. This simple hardware supported a simple, small system. `a.out` was completely adequate for the job of representing binaries on this simple system (a PDP-11). As people ported UNIX from this simple system, they retained the `a.out` format because it was sufficient for the early ports of UNIX to architectures like the Motorola 68k, VAXen, etc. Then some bright hardware engineer decided that if he could force software to do some sleazy tricks, then he would be able to shave a few gates off the design and allow his CPU core to run faster. While it was made to work with this new kind of hardware (known these days as RISC), `a.out` was ill-suited for this hardware, so many formats were developed to get to a better performance from this hardware than the limited, simple `a.out` format could offer. Things like COFF, ECOFF, and a few obscure others were invented and their limitations explored before things seemed to settle on ELF. In addition, program sizes were getting huge and disks (and physical memory) were still relatively small so the concept of a shared library was born. The VM system also became more sophisticated. While each one of these advancements was done using the `a.out` format, its usefulness was stretched more and more with each new feature. In addition, people wanted to dynamically load things at run time, or to junk parts of their program after the init code had run to save in core memory and swap space. Languages became more sophisticated and people wanted code called before main automatically. Lots of hacks were done to the `a.out` format to allow all of these things to happen, and they basically worked for a time. In time, `a.out` was not up to handling all these problems without an ever increasing overhead in code and complexity. While ELF solved many of these problems, it would be painful to switch from the system that basically worked. So ELF had to wait until it was more painful to remain with `a.out` than it was to migrate to ELF. ELF is more expressive than `a.out` and allows more extensibility in the base system. The ELF tools are better maintained, and offer cross compilation support, which is important to many people. ELF may be a little slower than `a.out`, but trying to measure it can be difficult. There are also numerous details that are different between the two in how they map pages, handle init code, etc. None of these are very important, but they are differences. ## For More Information ### Manual Pages The most comprehensive documentation on DragonFly is in the form of manual pages. Nearly every program on the system comes with a short reference manual explaining the basic operation and various arguments. These manuals can be viewed with the `man` command. Use of the `man` command is simple: % man command `command` is the name of the command you wish to learn about. For example, to learn more about `ls` command type: % man ls The online manual is divided up into numbered sections: 1. User commands. 1. System calls and error numbers. 1. Functions in the C libraries. 1. Device drivers. 1. File formats. 1. Games and other diversions. 1. Miscellaneous information. 1. System maintenance and operation commands. 1. Kernel internals. In some cases, the same topic may appear in more than one section of the online manual. For example, there is a `chmod` user command and a `chmod()` system call. In this case, you can tell the `man` command which one you want by specifying the section: % man 1 chmod This will display the manual page for the user command `chmod`. References to a particular section of the online manual are traditionally placed in parenthesis in written documentation, so [chmod(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=chmod§ion=1) refers to the `chmod` user command and [chmod(2)](http://leaf.dragonflybsd.org/cgi/web-man?command=chmod§ion=2) refers to the system call. This is fine if you know the name of the command and simply wish to know how to use it, but what if you cannot recall the command name? You can use `man` to search for keywords in the command descriptions by using the `-k` switch: % man -k mail With this command you will be presented with a list of commands that have the keyword ***mail*** in their descriptions. This is actually functionally equivalent to using the `apropos` command. So, you are looking at all those fancy commands in `/usr/bin` but do not have the faintest idea what most of them actually do? Simply do: % cd /usr/bin % man -f * or % cd /usr/bin % whatis * which does the same thing. ### GNU Info Files DragonFly includes many applications and utilities produced by the Free Software Foundation (FSF). In addition to manual pages, these programs come with more extensive hypertext documents called `info` files which can be viewed with the `info` command or, if you installed **emacs** , the info mode of **emacs** . To use the [info(1)](http://leaf.dragonflybsd.org/cgi/web-man?command=info§ion=1) command, simply type: % info For a brief introduction, type `h`. For a quick command reference, type `?`.