Appendix H. Tips for New Linux Users
这份安装指南假设用户至少具有对Linux技术与术语有基本的了解。在该部分,我们提供了一些可能对Linux新手有帮助的Tips。鉴于这些tips仅用于安装与设置NVIDIA驱动时阐明与帮助用户,它并不能被当作是一份Linux操作系统的使用及管理教程。不像其他一些桌面操作系统,在Linux上你很容易就会犯下对系统的不可挽回的错误。如果你对Linux的使用并不熟悉,我们强烈建议你在行动前找一份与你的Linux发行版相关的教程。
The command prompt-命令提示符
尽管最新的Linux发行版都带有全新的桌面界面,很多Linux中的任务仍然需要在命令提示符中完成。如果你对Windows操作系统比较熟悉,Linux中的命令提示符与Windows中的命令提示符很相似,尽管语法和使用稍有些不同。该部分中的所有命令都是在命令提示符下执行的。某些系统被设置成启动进入控制台模式,此时用户以命令提示符形式登录。另外的系统则设置成启动进入X windos系统,此时用户必须打开一个终端或者一个控制台窗口以得到一个命令提示符。这项工作一般可以通过在桌面菜单中搜索terminal或者console来完成。鉴于命令提示符是可以自定义的,基本的命令提示符一般由一串包含信息的短字符串、#,$,%三个字符之一以及一个游标(通常是在闪动的),用于指示用户的输入将被显示的位置。
Navigating the directory structure-游历目录结构
Linux具有一个分层的目录结构。在目录结构中的任意位置,ls命令将列出当前目录的内容。file命令将显示某目录中的文件类型。例如:
% file filename将显示文件filename的文件类型。更改目录由cd命令完成。
% cd dirname将切换当前工作目录到目录dirname。在目录结构中的任意位置执行pwd将显示当前工作目录的目录名。Linux中有两个特殊的目录名,.和..,前者代表当前工作目录,后者代表当前工作目录的父目录。对于任何需要以文件名或者目录名作为参数的命令,你可以给出对象的绝对路径或者相对路径。绝对路径以“/”开头,代表目录结构的顶端或者根部。相对路径以当前工作目录中的某个目录开始。相对路径可能以.或者..开始。路径的组成功元素以“/”隔开。例如,如果当前的工作目录是/home/yegle,用户希望切换到/usr/local目录中去,他可以任选以下两个命令中的一个来做到:
% cd /usr/local
或者
% cd ../../usr/local
File permissions and ownership-文件权限及所有权
所有文件及文件夹都有与之相关的文件权限及所有权。这可以有效地防止非管理员用户对系统的无意(或恶意)损坏。可以通过在ls命令后加-l选项来了解一个文件或者目录的权限及所有权。例如:
% ls -l
drwxr-xr-x 2 yegle users 4096 Feb 8 09:32 bin
drwxrwxrwx 10 yegle users 4096 Feb 10 12:04 pub
-rw-r--r-- 1 yegle users 45 Feb 4 03:55 testfile
-rwx------ 1 yegle users 93 Feb 5 06:20 myprogram
-rw-rw-rw- 1 yegle users 112 Feb 5 06:20 README
输出结果中,第一部分第一列字符给出了文件类型,其中“d“表示一个目录,”-“表示一个正常文件。接下来的9列详细给出了文件(夹)的权限(详见下文)。第二部分给出了与该文件(夹)相关联的文件数,第三部分给出了文件(夹)的拥有者,第四部分给出了该文件(夹)相关的用户组,第五部分给出了文件(夹)的字节数,第六、七、八部分给出了文件(夹)的最后修改时间,第九部分是文件(夹)的名称。
如前所述,第一部分的后九列给出了文件(夹)的权限。这几列被分为3组,第一组给出了文件拥有者(这里是yegle)的权限,第二组给出了与该文件(夹)相关的用户组的权限,第三组给出了其余用户的权限。r,w,x分别代表读、写、执行权限。例如,用户yegle有对testfile的读、写权限,在users用户组中的用户只有读权限,其余用户同样只有读权限。然而,对文件myprogram,用户yegle有读、写、执行权限(假设myprogram是一个可被执行的程序),同时用户组users和其余的用户没有任何权限(例如文件所有者不想任何人执行他的程序)。文件的权限、所有权和与之相关的用户组可以分别通过命令chmod,chown和chgrp来修改。如果一个拥有适当权限的用户想把某README文档的用户/用户组从yegle/users转到joe/admin,他需要以下几个步骤:
# chown joe README# chgrp admin READMEThe 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 myprogramThe 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 Linux 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 $SHELLYou can start a new shell simply by entering the name of the shell from the command prompt:
% cshor
% shand 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 myprogramThe 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 $MYVARIABLECommands 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 Linux 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 (see the section on Linux 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 Linux 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).
Booting to a different runlevel
Runlevels in Linux dictate which services are started and stopped automatically when the system boots or shuts down. The runlevels typically range from 0 to 6, with runlevel 5 typically starting the X window system as part of the services (runlevel 0 is actually a system halt, and 6 is a system reboot). It is good practice to install the NVIDIA Linux Driver while X is not running, and it is a good idea to prevent X from starting on reboot in case there are problems with the installation (otherwise you may find yourself with a broken system that automatically tries to start X, but then hangs during the startup, preventing you from doing the repairs necessary to fix X). Depending on your network setup, runlevels 1, 2 or 3 should be sufficient for installing the Driver. Level 3 typically includes networking services, so if utilities used by the system during installation depend on a remote filesystem, Levels 1 and 2 will be insufficient. If your system typically boots to a console with a command prompt, you should not need to change anything. If your system typically boots to the X window system with a graphical login and desktop, you must both exit X and change your default runlevel.
On most distributions, the default runlevel is stored in the file /etc/inittab, although you may have to consult the guide for your own distribution. The line that indicates the default runlevel appears as
id:n:initdefault:or similar, where n indicates the number of the runlevel. /etc/inittab must be edited as root. Please read the sections on editing files and root user if you are unfamiliar with this concept. Also, it is recommended that you create a copy of the file prior to editing it, particularly if you are new to Linux text editors, in case you accidentally corrupt the file:
# cp /etc/inittab /etc/inittab.originalThe line should be edited such that an appropriate runlevel is the default (1, 2, or 3 on most systems):
id:3:initdefault:After saving the changes, exit X. After the Driver installation is complete, you may revert the default runlevel to its original state, either by editing the /etc/inittab again or by moving your backup copy back to its original name.
Different distributions provide different ways to exit X. On many systems, the init utility will change the current runlevel. This can be used to change to a runlevel in which X is not running.
# init 3There are other methods by which to exit X. Please consult your distribution.
Linux 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 commandnameat the command prompt, where commandname refers to the command in which you are interested. Similarly, entering
% info commandnamewill 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. See the section on environment variables.


afeikuo7 于 2012-07-18 09:14:00发表:
呃~~~~~~~~~~~~~~~~