📄 unx02.htm
字号:
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I7" NAME="I7">
<FONT SIZE=3><B>After Login Succeeds</B>
<BR></FONT></A></CENTER></H4>
<P>After a successful login, several messages appear on your screen. Some of these may be the date and time of your last login, the system's informative message (called the "Message of the Day"), and a message informing you whether you have
(electronic) mail. The Message of the Day can be an important message to watch because it is one way that administrators communicate with the system users. The next scheduled down time (when no one can use the system) is an example of information that you
might see here.
<BR></P>
<P>After all the messages scroll by, the system is ready and waiting for you to do something. This ready-and-waiting condition is signified by a prompt followed by a cursor. Typical prompts are $ or %. The dollar-sign prompt is commonly used by Bourne and
Korn shells and the percent sign by c-shells. The value of this prompt (your primary prompt) can be changed if you wish. The person who set up your account may have already configured a different prompt value. To change this prompt, you need to change the
value of the environment variable PS1 (for Bourne and Korn) or prompt (for C shell). (See the section "Configuring Your Environment" in this chapter for details on environment variables.) The cursor (the spot on the screen where the next
character you type is displayed) is commonly an underline (_) or a box, either of which can be blinking. The cursor you see may vary from system to system.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I8" NAME="I8">
<FONT SIZE=3><B>Different Priviledges for Different Users</B>
<BR></FONT></A></CENTER></H4>
<P>If you are administering your own personal system, it is still important for you to set up a personal account for yourself, even though your system will come configured with some type of administrative account. This account should be used to do
system-wide administrative actions. It is important to be careful when using this account because it has special privileges. UNIX systems have built-in security features. Most users cannot set up a new user account or do other administrative procedures.
The user "root" is a special user, sometimes called super-user, which can do anything at all on the system. This high degree of power is necessary to fully administer a UNIX system, but it also allows its user to make a mistake and cause system
problems. For this reason, you should set up a personal account for yourself that does not have root privilege. Then, your normal, day-to-day activities will affect only your personal environment and you will be in no danger of causing system-wide
problems. In a multiuser, nonpersonal environment, you will most likely have only user (and not super-user) privileges. This security is even more important when more than one person is involved because one mistake by the root can affect every user and the
entire system.
<BR></P>
<P>UNIX also has security to help prevent different users from harming each other on a multiuser system. Each user "owns" his or her environment and can selectively let groups or all others have access to this work. If you are doing private work
in one area that no one else should be allowed to see, then you should restrict access to the owner (you). If you and your team members are working on a group project, you can restrict access to the owner (you) and everyone in your group. If this work
should be shared with many or all people on the system, then you should allow access to everyone.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I9" NAME="I9">
<FONT SIZE=4><B>Logging Out</B>
<BR></FONT></A></CENTER></H3>
<P>When you are done using the system, you should log out. This will prevent other people from accidentally or intentionally getting access to your files. It will also make the system available for their use.
<BR></P>
<P>The normal way to log out from almost any shell is to type exit. This causes your shell to exit, or stop running. When you exit from your login shell, you log out. If you are using csh, you can also type logout; if you are in a login shell, then csh
will log out. Some shells, depending on your configuration, will also log you out if you type the end-of-file character (typically Control+D; see "Working on the System" later in this chapter).
<BR></P>
<P>If you have a graphical user interface, your logout procedure may be different. Please consult your manuals or online help to learn about logging out of your GUI.
<BR></P>
<H3 ALIGN="CENTER">
<CENTER><A ID="I10" NAME="I10">
<FONT SIZE=4><B>Using Commands</B>
<BR></FONT></A></CENTER></H3>
<P>During the login process described in the section, "Logging In" UNIX performs several actions that prepare you and the system for each other. These include performing system accounting, initializing your user environment, and starting a
command interpreter (commonly called a shell). Commands are how you tell the system to do something. The command interpreter recognizes these commands and passes the information off to where it is needed. UNIX systems originally came with a command
interpreter called the Bourne Shell (usually referred to as sh, though some systems ship Korn or POSIX as sh—see the Note that follows). This shell is still available on most UNIX computer systems. A newer shell that is common to most UNIX systems is
the C Shell (referred to as csh). Another commonly used, but not as pervasive, shell is the Korn Shell (referred to as ksh). Among different shells, there is some variation of the commands that are available. Refer to Part II, "Hunt for Shells,"
for details on these UNIX shells.
<BR></P>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> What's in a name?
<BR>
<BR>There are a number of different common shells on various UNIX operating systems. The most common are as follows:
<BR>
<BR>sh The Bourne shell is the most common of all
<BR> the shells. (May be installed as bsh.)
<BR>
<BR>sh The POSIX shell is much like the Korn shell.
<BR> The POSIX standard requires it to be
<BR> installed as sh. Some vendors install it as
<BR> /bin/sh. Some put it in a special directory
<BR> and call it sh, leaving the Bourne shell as
<BR> /bin/sh.
<BR>
<BR>ksh The Korn shell is a derivative of the Bourne
<BR> shell, which adds history and command-line
<BR> editing. (Sometimes installed as sh.)
<BR>
<BR>csh The C shell is based on the popular C
<BR> language.
<BR>
<BR>bash The Born Again shell is less common.
<BR>
<BR>tcsh This is a version of the C shell with
<BR> interactive command-line editing.
<BR></NOTE>
<HR ALIGN=CENTER>
<H4 ALIGN="CENTER">
<CENTER><A ID="I11" NAME="I11">
<FONT SIZE=3><B>What Is a Command?</B>
<BR></FONT></A></CENTER></H4>
<P>A UNIX command is a series of characters that you type. These characters consist of words that are separated by whitespace. Whitespace is the result of typing one or more Space or Tab keys. The first word is the name of the command. The rest of the
words are called the command's arguments. The arguments give the command information that it might need, or specify varying behavior of the command. To invoke a command, simply type the command name, followed by arguments (if any), to indicate to the shell
that you are done typing and are ready for the command to be executed, press Enter.
<BR></P>
<P>Try it out. Enter the date command. The command's name is "date" and it takes no arguments. Therefore, type date and press Enter and see what happens. You should see that the computer has printed the current date and time. If the date or time
does not match reality, ask the system administrator to fix it. How about trying a command that has arguments? Try the echo command. The name of the command is "echo" and it takes a series of arguments. The echo command will then write, or echo,
these arguments out to your screen. Try creating a command that will write your first and last name on the screen. Here is what these commands and output look like on our system:
<BR></P>
<PRE>$ date
Sat Mar 5 11:11:00 CST 1994
$ echo Arnold Brimmer
Arnold Brimmer
$</PRE>
<HR ALIGN=CENTER>
<NOTE>
<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B> Some commands such as echo are part of the particular shell you are using. These are called built-ins. In this case, the commands are not standard from one shell to another. Therefore, if you learn
one shell and then later have to (or want to) switch to using a different shell, you may have to learn new commands (and unlearn others). Other commands are standard UNIX commands and do not depend on what shell you are using. These should be on every UNIX
system. The remaining commands are nonstandard UNIX and may or may not be on a particular UNIX system.
<BR></NOTE>
<HR ALIGN=CENTER>
<P>UNIX commands use a special type of argument called an option. An option commonly takes the form of a dash (made by using the minus sign key) followed by one or more characters. The options provide information to the command. Most of the time, options
are just a single character following a dash. Two of the other lesser used forms are a plus sign rather than a minus sign, and a word following a dash rather than a single character. The following paragraph shows a common command with two of its common
options. The ls command lists the files in your current directory.
<BR></P>
<P>First, try the ls command with no arguments. Then, try it with the -a option and note that the directory listing contains a few files that start with a period. These hidden files get listed by the ls command only if you use the -a option. Next, try the
ls command with the -l option. This option changes the format of the directory listing so that each file is displayed along with some relevant details. Finally, try the ls command with both of these options, so that your command is as follows: ls -a -l.
<BR></P>
<PRE>$ <B>ls</B>
visible
$ ls -a
. .. .hidden visible
$ ls -l
total 0
-rw-rw-rw- 1 sartin uu 0 Mar 5 12:58 visible
$ ls -a -l
total 16
drwxrwxrwx 2 sartin uu 1024 Mar 5 13:03 .
drwxr-xr-x 37 sartin uu 3072 Mar 5 13:03 ..
-rw-rw-rw- 1 sartin uu 0 Mar 5 12:58 .hidden
-rw-rw-rw- 1 sartin uu 0 Mar 5 12:58 visible
$</PRE>
<P>A command developer often tries to choose option letters that are meaningful. Regarding the ls command, you might think of the -a as meaning that "all" files should be listed (including the special files starting with period). And you might
think of the -l option as meaning a "long" directory listing because the format is changed so that each line contains one file along with its details. This makes for a longer listing.
<BR></P>
<H4 ALIGN="CENTER">
<CENTER><A ID="I12" NAME="I12">
<FONT SIZE=3><B>Redirecting Input and Output</B>
<BR></FONT></A></CENTER></H4>
<P>One very pervasive concept in UNIX is the redirection of commands' input and output. Before looking at redirection, though, it is a good idea to look at input and output without modification. UNIX uses the word standard in this subject to mean the
default or normal mode. Thus, UNIX has the term standard input, which means input coming from the default setting, and the term standard output, which means output going to the normal place. When you first log in to the system, and your shell executes,
your standard input is set to be what you type at the keyboard, and your standard output is set to be your display screen. With this in mind, follow along with the example.
<BR></P>
<P>The cat command takes any characters from standard input, and then echoes them to standard output. For example, type the cat command, with no arguments. Your cursor should be sitting on the next line without a prompt. At this point, the cat command is
waiting for you to enter characters. You can enter as many as you like, and then you should specify that you are finished. Type a few words and then press Return. Now type the special character, Control+D (hold down the Control key while typing the D key).
This is the "eof" control character. (See "Working on the System" later in this chapter for a description of control characters.) The words you typed should be on your screen twice—once caused by you entering them from the
keyboard, and next as the cat command outputs them to your screen. This first step used standard input (from you typing on the keyboard), and standard output (the command results being printed on the screen).
<BR></P>
<PRE>$ <B>cat</B>
s
A few words
<CTRL><D>
A few words
$ cat > scotty
Meow, whine
meow
<CTRL><D>
$ cat < scotty
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -