什么是 unix? The Unix operating system comprises three parts: The Kernel, The Standard Utility Programs, and The System Conf" name="description" />

Unix基础

发表于:2007-07-04来源:作者:点击数: 标签:
S1. What is Unix? MI LY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">什么是 unix? The Unix operating system comprises three parts: The Kernel, The Standard Utility Programs, and The System Conf

S1. What is Unix? MILY: 宋体; mso-ascii-font-family: 'Times New Roman'; mso-hansi-font-family: 'Times New Roman'">什么是unix?

The Unix operating system comprises three parts: The Kernel, The Standard Utility Programs, and The System Configuration Files

Unix 操作系统是由3部分组成的:内核,标准工具程序和系统配置文件.

 

1.The Kernel: It's the core of the unix operating system. A large program that is loaded into memory when the machine is turned on, and it controls the allocation of hardware resources from that point forward. It has the necessary programs to talk to all the devices connected to it.

  内核:它是unix操作系统的核心。当计算机启动的时候,大的程序会被读取到内存当中,

并且控制硬件资源的分配。它拥有必要的程序来与他连接的所有设备进行对话。

 

2.The Standard Utilities Programs: It includes simple utilities like "cp", and complex utilities like the shell that allows u to issue commands to the operating system.

 标准工具程序:它包含了简单有效的命令,比如像“cp”,也有复杂的shell,使你可以向操作系统传达指令。

 

3.The System configuration Files: It is read by the kernel and some of the standard utilities. The unix kernel and the utilities are flexible programs, and certain aspects of their behavior can be controlled by changing the standard configuration files.

 系统配置文件:它是被内核和一些标准工具来读取使用的。Unix内核和工具是灵活易用的程序。他们的某些特性可以被标准的系统配置文件来改变。

 

eg. A system configuration files is the filesystem table "fstab", which tells the kernel where to find all the files on the disk drives. The system log configuration file "syslog.conf", which tells the kernel how to record the kinds of events and errors it may encounter.

 例如:系统配置文件是一个文件系统表“fstab,由它来通知内核在磁盘驱动器上到哪里去找文件。系统日志配置文件是“syslog.conf,由它来通知内核如何去纪录不同的事件和它有可能碰到的错误。

 

S2. Aclearcase/" target="_blank" >ccessing a Unix System 访问unix系统

The main mode of access to a Unix machine is through a terminal, which usually includes a keyboard, and a video monitor. Each Terminal connected to Unix system, the kernel runs a process called a tty that accepts input from the terminal, and sends output to the terminal. TTY processes must be told the capabilities of the terminal to correctly read from, and write to ,the

terminal.

 访问unix机器的主要模式是通过终端来进行的,通常是由一个键盘,和一个显示器来组成的。每一个终端都连接到unix的系统上,内核来运行一个程序被称作tty,一个专门从终端接受输入信息,并且传送输出到终端的程序。TTY程序必须要去判断终端的实际能力,让它正确的去读取核写入信息到终端当中去。

 

Console: A special type of terminal. Some unix system operations must be performed at the console. Only accessible by the system operators, and administrators.

控制台:一个特殊的终端类型。一些unix系统的操作必须要在控制台运行。只允许系统操作员和管理员有此权限。

 

Dumb terminals: They have only the minimum amount of power required to send characters as input to the unix system. Personal computers are often used to emulate dumb terminals.

哑终端:它们只有最小的功率来传送必须的字符就像输入到unix系统一样。个人计算机经常被用作模仿哑终端。

 

Smart terminals: Just like X terminal.(瘟死你的操作系统形式)

 

S3. Logging in and logging out 登陆和退出

A system of user accounts. To be used ,to ensure security and organization on a system with many user.

使用者账户系统。被用作在系统上对用户进行组织管理和确保账号的安全

 

S4. The Unix shell

It is the most important program on the unix system, from the end-user's standpoint, interface with Unix system, the middleman between u and the kernel.

它是unix系统上非常重要的程序,从终端用户的角度来说,它是介于使用者和内核之间的中间接口

Concept: а. The shell is a type of program calls an 'interpreter'. Shell是一个解释程序

                                   

        б. A program is referred to as a 'process', while the kernel is running it simultaneously.

           当内核在同时的运行它的时候,这个程序被称作“进程“

        с. Execute a non built-in shell command, the shell asks the kernel to create a new

      subprocess (called a "child" process) to perform the command.

        如果执行一个非shell内建命令,那么shell会告诉内核去创建一个新的子进程来完成这个指令。

 

 

S5. Working with Files and Directories

1.The Unix filesystem structure: unix 文件系统结构

Concept: The unix filesystem is resembling a tree structure. Anchored at a place called the 'root', designated by a slash "/".

概念:unix的文件系统很像一棵树的结构。固定的那个位置被称作‘root’使用“/”符号来表示。

                                 

eg.  ls -l /etc/passwd

    -rw-r--r-- 1 root sys 41002 Nov 17 13:00 /etc/passwd

The first dash indicates the type of file(d for directory, s for special file,-for a regular file)

"rw-" permissions of the owner of the file: read and write, but no execute. "r--" permissions for those in the same group as the owner: read, no write, no execute. "r--" permission for all others: read, no write, no execute.

第一个破折号表示文件的类型(d 代表目录,s代表特殊文件,-代表一个普通文件)

rw-”文件所有者的权限:读和写,不能执行。

r--”对于在同一组的文件所有者的权限:读,不能写和执行。

r--”其他权限:读,不能写和执行

Setting permissions: use command "chmod"

"rwx" notation to specify the type of permission

"ugo" notation to specify those the permission apply to

add permission:+

remove permission:-

set a permission directly:=

eg. chmod g=rw- ~/.shrc ( ~ unix shorthand for your home directory)

    pwd => " print working directory"

    ls -lr /etc/i* ( * 通配符)

The cat command: it concatenates files and sends them to the screen.

# cat ~/.profile

# head -15 /etc/rc to see the first 15 lines of the /etc/rc file

# tail /etc/rc to see the last 10 lines(default 10 lines, u can change it)

Copying files and directories:

cp source destination

eg. cp ~/.profile ~/pcop

Moving and renameing files:

# mv ~/pcop ~/qcop

Removing files: rm filename

#rm ~/.pcop

Creating a directory:

mkdir directoryname

# mkdir ~/cry

# mkdir ~/cry/los

Removing a directory:

# rmdir ~/cry/los

# rmdir ~/cry

 

S6. Redirecting Input and Output 改变输入输出

Concept: Every program u run from the shell opens three files: Standard input , Standard output, and Standard error.

概念:你从shell运行的每一个程序,都会打开3个文件:标准输入,标准输出,标准错误。

The standard input file provides a way to send data to a process. As a default, it is read from the terminal keyboard. The standard output provides a means for the program to output data. As a default, it goes to the terminal display screen. The standard error is where the program reports any errors encountered during execution. By default, the standard error goes to the terminal display.

标准输入文件提供了一个将数据传送到一个进程的方法。作为默认的设置,它从终端的键盘读取数据。标准输入为程序提供了输出数据的方法。作为默认的设置,它通过终端在屏幕上显示。标准错误是程序在执行当中可能报告的错误。同样的作为默认设置,错误信息会在终端的屏幕上显示出来。

 

Unix uses the “less than” and “greater than” special characters () to signity input and output redirection, respectively.

Redirecting input:

“less-than” sign: # < file1

# more < /etc/passwd

# head /etc/passwd    work just the same as   # head < /etc/passwd

 

Redirecting output:

“greater-than” sign: # > file2 (如果file2已经存在,会被新的覆盖)

Redirecting error: In the POSIX shell and ksh, redirect the standard error with the symbol “2>”

eg. sort the /etc/passwd file, place the results in a file called cry, and trap any errors in a file

called err:

# sort cry 2>err

 

S7. Pipelines and Filters 管道和过滤

Concept: Unix allows u to connect processes, by letting the standard output of one process feed into the standard input of another process. That mechanism is called a Pipe.

概念:unix允许你连接进程,就是将一个进程的标准输出插入到另外一个进程的标准输出。这种体系结构被称作管道。

eg. # cat .profile .shrc | more

   # cat file | head –75 | tail – 50 (display lines 25 through 75 of a file)

Remember that input/output redirection connects processes with files, while the pipe connects processes with other processes.

Grep(文件内字符串查找):

grep [-options] pattern[file]

It is always best to enclose the pattern within single quotes, to prevent the shell from misinterpreting the command.

Characters can use to build grep expressions:

lANT: normal" times="" new="">         The carat (^) matches the beginning of a line

l         The dollar sign ($) matches the end of a line.

l         The period (.) matches zero or more occurrences of the previous character.

l         The expression [a-b] matches any characters that are lexically between a and b.

eg.  # grep  ‘cry’   /etc/passwd  (the lines containing the string “cry”.)

# grep  ‘^cry’  /etc/passwd  (the line begin with the character string “cry”.)

List all the files in the /tmp directory owned by the user root

# ls  –l  /tmp | grep ‘root’

 

S8. Process Control and Multitasking 进程控制和多任务处理

Concept: The Unix kernel can keep track of many processes at once, dividing its time between the jobs submitted to it. Each process submitted to the kernel is given a unique process ID. In reality, it is running only one job at a time, but quickly switching between all of its ongoing tasks. The concept of switching is called process scheduling.

概念:unix 内核可以并存多个线程,在任务之间划分时间然后提交给它。每一个进程提交给内核,并分配到一个唯一指定的进程ID。事实上,它每次只能执行一个任务,只是快速的在所有正在运行的任务之间进行切换而已。切换的概念被称作进程安排。

Viewing processes: ps (process status) for viewing the status of all the unfinished jobs that have been submitted to the kernel.

eg. # ps  -ef

   -e option causes ps to include all processes (indluding ones that do not belong to u), and –f option causes ps to give a long listing (include the process owner, the process ID, the ID of the parent process,  processor utilization, the time of submission, the process’s terminal, the total time for the process, and the command that started the process.)

eg. Use ps and grep, in a pipeling to find all the processes owned by u.

   # ps  -ef  |  grep  crystalos(here is your username)

Killing processes: Occasionally, u will find a need to terminate a process.

Kill [-options] process-ID

eg. To force termination of a job whose process ID is 111,enter:

  # ps  -9  111

 

S9 Interaction and job Control 交互和任务控制

Placing a foreground job into the background first thing u must do is suspend the job with a Control-Z, freeing your terminal. Then, u can issue the Unix command: bg

Bringing a background job to the foreground

将一个前端任务放到后台运行,你首要做的就是使用ctrl+z将任务暂停,解除终端。然后,输入命令:bg 将一个后台运行的任务放到前台来。

# fg  %2  will bring job 2 into the foreground. If no job ID is given, fg will assume u are referring to the current (suspended) job.

Starting a suspended job

Find the job ID of the suspended job with the jobs command, and then use bg or fg.

 

S10 The Execution Environment 执行环境

Concept: The exact behavior of commands issued in the shell depends upon the execution environment provided by the shell.

概念:在shell中准确的传达指令依赖于shell的执行环境。

To view all the environment variables, use: printenv

To view a particular environment variable, use: echo $TERM

The creation of the execution environment.

 

When u log in, a sequence of events establishes the execution environment. It depends on the particular flavor of Unix, and also depends upon the default shell for your account.

当你登陆到系统的时候,事件的进程确定执行环境。它取决于unix的类型,当然也依赖你账户的默认shell

For HP-UX operating system(other may differ):

The gritty process: it provides the login: prompt that u see on the terminal screen. It reads your username, and invokes login program.

The login program: trial and error verity to find your information in /etc/passwd, then to invoke your default shell. If doesn’t has default shell, login starts the Bourne shell (/bin/sh).

 

Shell startup: System login scripts

On HP-UX, the file /etc/.profile provides initialization parameters for ksh and sh, while the file /etc/csh.login is used for csh.

Shell startup: User login scripts

After the system login scripts are read, the shell reads user login scripts.

Important environment variables:

TERM,PATH,USER,HOME,MAIL,EDITOR,HOST

Setting environment and shell variables

The exact mechanism for it depends upon the type of shell u’re using.

sh, or ksh: VAR=value;export VAR

eg. EDITOR=emacs;export EDITOR  (注意:中间不要空格)

csh: setenv VARIABLE value

eg. Setenv EDITOR emacs

 

 

原文转自:http://www.ltesting.net