Chapter 8. Tips for New FreeBSD Users

This installation guide assumes that the user has at least a basic understanding of FreeBSD techniques and terminology. In this section we provide tips that the new user may find helpful. While the these tips are meant to clarify and assist users in installing and configuring the NVIDIA FreeBSD Driver, it is by no means a tutorial on the use or administration of the FreeBSD operating system. Unlike many desktop operating systems, it is relatively easy to cause irreparable damage to your FreeBSD system. If you are unfamiliar with the use of FreeBSD, we strongly recommend that you seek a tutorial through your distributor before proceeding.

The command prompt

While newer releases of FreeBSD bring new desktop interfaces to the user, much of the work in FreeBSD takes place at the command prompt. If you are familiar with the Windows operating system, the FreeBSD command prompt is analogous to the Windows[1] command prompt, although the syntax and use varies somewhat. All of the commands in this section are performed at the command prompt. Some systems are configured to boot into console mode, in which case the user is presented with a prompt at login. Other systems are configured to start the X window system, in which case the user must open a terminal or console window in order to get a command prompt. This can usually be done by searching the desktop menus for a terminal or console program. While it is customizable, the basic prompt usually consists of a short string of information, one of the characters #, $, or %, and a cursor (possibly flashing) that indicates where the user's input will be displayed.

Navigating the directory structure

FreeBSD has a hierarchical directory structure. From anywhere in the directory structure, the ls command will list the contents of that directory. The file command will print the type of files in a directory. For example,

    % file filename

will print the type of the file filename. Changing directories is done with the cd command.

    % cd dirname

will change the current directory to dirname. From anywhere in the directory structure, the command pwd will print the name of the current directory. There are two special directories, . and .., which refer to the current directory and the next directory up the hierarchy, respectively. For any commands that require a file name or directory name as an argument, you may specify the absolute or the relative paths to those elements. An absolute path begins with the "/" character, referring to the top or root of the directory structure. A relative path begins with a directory in the current working directory. The relative path may begin with . or ... Elements of a path are separated with the "/" character. As an example, if the current directory is /home/jesse and the user wants to change to the /usr/local directory, he can use either of the following commands to do so:

    % cd /usr/local

or

    % cd ../../usr/local

File permissions and ownership

All files and directories have permissions and ownership associated with them. This is useful for preventing non-administrative users from accidentally (or maliciously) corrupting the system. The permissions and ownership for a file or directory can be determined by passing the -l option to the ls command. For example:

% ls -l
drwxr-xr-x     2    jesse    users    4096    Feb     8 09:32 bin
drwxrwxrwx    10    jesse    users    4096    Feb    10 12:04 pub
-rw-r--r--     1    jesse    users      45    Feb     4 03:55 testfile
-rwx------     1    jesse    users      93    Feb     5 06:20 myprogram
-rw-rw-rw-     1    jesse    users     112    Feb     5 06:20 README
% 

The first character column in the first output field states the file type, where 'd' is a directory and '-' is a regular file. The next nine columns specify the permissions (see below) of the element. The second field indicates the number of files associated with the element, the third field indicates the owner, the fourth field indicates the group that the file is associated with, the fifth field indicates the size of the element in bytes, the sixth, seventh and eighth fields indicate the time at which the file was last modified and the ninth field is the name of the element.

As stated, the last nine columns in the first field indicate the permissions of the element. These columns are grouped into threes, the first grouping indicating the permissions for the owner of the element (jesse in this case), the second grouping indicating the permissions for the group associated with the element, and the third grouping indicating the permissions associated with the rest of the world. The r, w, and x indicate read, write and execute permissions, respectively, for each of these associations. For example, user jesse has read and write permissions for testfile, users in the group users have read permission only, and the rest of the world also has read permissions only. However, for the file myprogram, user jesse has read, write and execute permissions (suggesting that myprogram is a program that can be executed), while the group users and the rest of the world have no permissions (suggesting that the owner doesn't want anyone else to run his program). The permissions, ownership and group associated with an element can be changed with the commands chmod, chown and chgrp, respectively. If a user with the appropriate permissions wanted to change the user/group ownership of README from jesse/users to joe/admin, he would do the following:

    # chown joe README
    # chgrp admin README

The syntax for chmod is slightly more complicated and has several variations. The most concise way of setting the permissions for a single element uses a triplet of numbers, one for each of user, group and world. The value for each number in the triplet corresponds to a combination of read, write and execute permissions. Execute only is represented as 1, write only is represented as 2, and read only is represented as 4. Combinations of these permissions are represented as sums of the individual permissions. Read and execute is represented as 5, where as read, write and execute is represented as 7. No permissions is represented as 0. Thus, to give the owner read, write and execute permissions, the group read and execute permissions and the world no permissions, a user would do as follows:

    % chmod 750 myprogram

The shell

The shell provides an interface between the user and the operating system. It is the job of the shell to interpret the input that the user gives at the command prompt and call upon the system to do something in response. There are several different shells available, each with somewhat different syntax and capabilities. The two most common flavors of shells used on FreeBSD stem from the Bourne shell (sh) and the C-shell (csh) Different users have preferences and biases towards one shell or the other, and some certainly make it easier (or at least more intuitive) to do some things than others. You can determine your current shell by printing the value of the SHELL environment variable from the command prompt with

    % echo $SHELL

You can start a new shell simply by entering the name of the shell from the command prompt:

    % csh

or

    % sh

and you can run a program from within a specific shell by preceding the name of the executable with the name of the shell in which it will be run:

    % sh myprogram

The user's default shell at login is determined by whoever set up his account. While there are many syntactic differences between shells, perhaps the one that is encountered most frequently is the way in which environment variables are set.

Setting environment variables

Every session has associated with it environment variables, which consist of name/value pairs and control the way in which the shell and programs run from the shell behave. An example of an environment variable is the PATH variable, which tells the shell which directories to search when trying to locate an executable file that the user has entered at the command line. If you are certain that a command exists, but the shell complains that it cannot be found when you try to execute it, there is likely a problem with the PATH variable. Environment variables are set differently depending on the shell being used. For the Bourne shell (sh), it is done as:

    % export MYVARIABLE="avalue"

for the C-shell, it is done as:

    % setenv MYVARIABLE "avalue"

In both cases the quotation marks are only necessary if the value contains spaces. The echo command can be used to examine the value of an environment variable:

    % echo $MYVARIABLE

Commands to set environment variables can also include references to other environment variables (prepended with the "$" character), including themselves. In order to add the path /usr/local/bin to the beginning of the search path, and the current directory . to the end of the search path, a user would enter

    % export PATH=/usr/local/bin:$PATH:.

in the Bourne shell, and

    % setenv PATH /usr/local/bin:${PATH}:.

in C-shell. Note the curly braces are required to protect the variable name in C-shell.

Editing text files

There are several text editors available for the FreeBSD operating system. Some of these editors require the X window system, while others are designed to operate in a console or terminal. It is generally a good thing to be competent with a terminal-based text editor, as there are times when the files necessary for X to run are the ones that must be edited. Three popular editors are vi, pico and emacs, each of which can be started from the command line, optionally supplying the name of a file to be edited. vi is arguably the most ubiquitous as well as the least intuitive of the three. pico is relatively straightforward for a new user, though not as often installed on systems. If you don't have pico, you may have a similar editor called nano. emacs is highly extensible and fairly widely available, but can be somewhat unwieldy in a non-X environment. The newer versions each come with online help, and offline help can be found in the manual and info pages for each (please see the section on FreeBSD Manual and Info pages). Many programs use the EDITOR environment variable to determine which text editor to start when editing is required.

Root user

Upon installation, almost all distributions set up the default administrative user with the username root. There are many things on the system that only root (or a similarly privileged user) can do, one of which is installing the NVIDIA FreeBSD Driver. We must emphasize that assuming the identity of root is inherently risky and as root it is relatively easy to corrupt your system or otherwise render it unusable. There are three ways to become root. You may log in as root as you would any other user, you may use the switch user command (su) at the command prompt, or, on some systems, use the sudo utility, which allows users to run programs as root while keeping a log of their actions. This last method is useful in case a user inadvertently causes damage to the system and cannot remember what he has done (or prefers not to admit what he has done). It is generally a good practice to remain root only as long as is necessary to accomplish the task requiring root privileges (another useful feature of the sudo utility).

FreeBSD Manual and Info pages

System manual or info pages are usually installed during installation. These pages are typically up-to-date and generally contain a comprehensive listing of the use of programs and utilities on the system. Also, many programs include the --help option, which usually prints a list of common options for that program. To view the manual page for a command, enter

    % man commandname

at the command prompt, where commandname refers to the command in which you are interested. Similarly, entering

    % info commandname

will bring up the info page for the command. Depending on the application, one or the other may be more up-to-date. The interface for the info system is interactive and navigable. If you are unable to locate the man page for the command you are interested in, you may need to add additional elements to your MANPATH environment variable. Please see the section on environment variables.



[1] Windows is a registered trademark of Microsoft Corporation in the United States and other countries.