?? unix use and security from the ground up.htm
字號:
Shell-----sh -This is the Bourne shell, the standard shell of Unix System V, and the focus of this file. This shell gives user-level accounts a command prompt of "$", and "#" for superuser accounts. On Berkely BSD Unix, this shell gives an ampersand ("&") prompt.csh -This is the C shell, developed by the Berkely University Science department. This shell is pretty much the same as the Bourne shell, but features different shell programming control structures [shell programming will be explained later, in the section on Unix software development], and has a few luxuries such as aliasing (giving a command or a series of commands a new name), and it keeps a history of the commands you enter. This shell gives a "%" prompt for user accounts and a "#" prompt for superuser accounts. ksh -This is the new, Korn shell. This shell combines features of both the Bourne shell and the C shell. It boasts the Bourne shell's easier shell programming, along with the C shell's aliasing and history. Its prompts are "$" for users and "#" for superusers.rsh -This is the restricted Bourne shell. It is used for accounts that the superuser wishes to restrict the commands available to. It will not allow you to execute commands outside of your searchpath (which will be explained later, also, in the section on software development), and will not let you change directories or change the values of shell variables. In all other respects, it is similar to the Bourne shell. A later section of this file will detail ways to overcome the restrictions of this shell.ua -This is a lousy, menu-driven shell for the AT&T Unix PC. (Yes, there are some of those with dialups!) It implements a lousy windowing system that is SLOOOW, even at 2400 baud. Luckily, you can exit to the Bourne shell from the ua shell. These are by no means all of the shells you will run across. These are only the "official" shells provided by the distributors of the Unix operating system. I've run across many "home-made" shells in my time. Also, any compiled program can be used as a shell. For instance, I've used systems run by businesses where one account logged in using an accounting program as a shell. This prevented the account from being used to do anything other than use the accounting program. Other good examples of this are the command logins-the who command login, for example, uses the who program as its shell. When the program is finished, the account is logged out. You will most definitely encounter other such accounts as you hack Unix.UNIX FILES AND DIRECTORIES-------------------------- Unix files and directories are referenced with pathnames, a la MS-DOS.If you are familiar with MS-DOs, then you should have no problem understanding this section. Unix files and directories are referenced in the almost the exact same way-the only difference is that it uses the "/" character, not the backslash, to separate the directories in the pathname. Pathnames are a simple concept to understand, but are difficult to explain. Imagine the system's files and directories laid out in a tree fashion, like this: / (root directory) : : ------------------------- : : : : usr (dir) bill (dir) : : -------------- -------------- : : : : junk (file) source (dir) memo (file) names (file) :"/" is the root directory. This is the top directory in the system tree, and all other files and directories are referenced in relation to this directory. The root directory has 2 subdirectories in it, "usr" and "bill". In the usr directory, there is a file called "junk" and an empty directory called "source". In the directory bill, there are 2 files, "memo" and "names". You specify pathnames by starting at the top of the system, "/", and tracing your way down the system tree to the file or directory you wish to reference, separating each directory you must pass through to get to it with a slash. For instance, the pathname of the file "junk" would be "/usr/junk". The pathname of the usr directory would be "/usr". The pathname of the source directory would be "/usr/source". The pathname of the bill directory would be "/bill", and the pathnames of the 2 files which reside in it would be "/bill/memo" and "/bill/names". Files and directories can also be referenced by their base names if they are in your current directory. For instance, if you were in the directory "usr", you could reference the file "/usr/junk" by its base name, "junk". If you were in the root directory, you could reference the bill directory by its base name, "bill". You can reference the file directly above your current directory in the system tree as ".." and your current directory can be referenced as "." Unix file and directory names can be up to 14 characters in length. Thefilename can contain any ASCII character, including control characters, excepta space. It may contain both upper- and lower-case, and Unix does distinguishbetween the two. Unix does not use filename extensions, a la VMS or MS-DOS, to show the kind of file a file is. A period, in Unix, is just another character in the filename, not a separator between 2 fields in the name. File names which begin with a period are called "hidden" files-that is, they are only revealed if you issue a special command. There are 3 kinds of files in Unix. These are text files, binary files,and device files. Text files are just what you'd think they are from the name-files of ASCII text, just like what you're reading right now. Binary files areexecutable machine-code files. (There are also executable text files, called shell scripts, that will be explained in detail in the section on Unix software development.) Device files are files that represent the system's I/O devices-disk drives, terminals, etc. Remember, that Unix was created as an enviroment for software development. Its designers wished for programs written for Unix systems to be as transportable between different models of machines running the operating system as possible. By representing the I/O devices as files, they eliminated the incompatability in the code that handled I/O. The program simply has to read and write from/to the file, and the Unix operating system handles the system-dependant details.BASIC UNIX COMMANDS------------------- This section will describe some basic Unix commands, and detail how to get further help on-line. It will briefly provide the syntax for a few commands you will find necessary to know in order to find your way around on the system. Unix will usually only require that you use the base name of a file or directory you wish to reference if it is in the directory you are currently in. Most commands will also let you specify full pathnames if you wish to reference files in other parts of the system. Most commands will also let you use several wildcard characters when referencing files and directories. These are:? -This means to accept any single character in the place of the question mark. For instance, "t?m" would include both "tom" and "tim".* -This means to accept any character, group of characters, or nothing in the position of the asterisk. For example, "t*m" would include "thom", "tom", and "tim".[] -This means to accept any character within the brackets in the position of the brackets. For instance, "t[oia]m" would include "tom", "tim", and "tam". You can also specify a range of characters in the brackets by using a hyphen. For instance, "t[a-c]m" would include "tam", "tbm", and "tcm". Most commands and programs in Unix take their input from the keyboard and send their output to the screen. With most commands and programs, however, you can instruct them to draw their input from a text file and redirect their output to another file instead. For instance, assume there is a program on the system called "encrypter", that takes its input from the keyboard, encrypts it, and displays the encrypted data on the screen. You could instruct the program to take its input, instead, from a previously prepared text file using the input redirection character, "<". In Unix, as in MS-DOs (which is based in part on Unix), you execute a program by typing its name. You wish the program to take its input from a file in the directory you are currently in called "top_secret". You would type "encrypter < top_secret". The program would then read in the contents of the file top_secret and encrypt it, then print out the encrypted form on the screen. Suppose you wanted to use the encrypter program to encrypt files you wished to keep private? You could redirect the encrypted output from the screen into another file. To do this, you would use the output redirection character, ">". Say, you wished to save the output in a file called "private". You would type "encrypter < top_secret > private". The encrypter program would then read in the contents of the file top_secret and write the encrypted output into the file "private". Nothing would be displayed to the screen. If the file private does not exist, it will be created. If it previously existed, its contents will be erased and replaced with the output from the encrypter program. Perhaps you would want to add to the contents of a file rather than replace its contents? This is done with ">>". The command "encrypter < top_secret >> private" would append the output from the encrypter to the current contents of the file private. Again, if the file private does not already exist, it will be created. Most commands have one or more options that you can specify. These are placed after the command itself in the command line, and preceded by a hyphen. For instance, let's say that the encrypter program had an option called "x", which caused it to use a different encoding algorithm. You would specify it by typing "encrypter -x". If a command has two or more options, youcan usually specify one or more together in a stream. For instance, let's say that the encrypter program has 2 options, x and y. You could specify both like this: "encrypter -xy". If one or more of the options requires an argument, for example the x option requires a 2 character key, you can specify the options separately, like this: "encrypter -xaa -y", where aa is the 2-character key. The pipe character, "|", is used to channel the output of one command or program into the input of another. For instance, suppose you had a command called "report" that formatted documents into report format, and you had a file called "myreport" that you wished to view in the report format. You could type:"cat myreport" | report". This would type out the contents of the file myreport to the report command rather than the screen, and the report command would format it and display it on the screen. (Note: this example could have been done with I/O redirection by typing "report < myreport"...but it makes a good example of the use of pipes.) You can choose to execute commands and programs in the background-that is, the command executes, but you are free to carry out other tasks in the meantime. To do this, type in the command line, followed by " &". For instance, "rm * &" would delete all the files in the directory, but your terminal wouldnot be tied up. You would still be free to perform other tasks. When you do this, the system will print out a number and then return you to the system prompt. This number is the process number of the command. Process numbers will be explained later in this section in the entry for the command "ps". The command can be stopped before its completion with the kill command, also explained in this section. Example: $rm * & 1234 $Note that when you use background processing, the command or program will still takes its input from the keyboard (standard input device) and send its output to the screen (standard output device), so if you wish for the command to work in the background without disturbing you, you must redirect its input (if any) and its output (if it's to the screen).THE COMMANDS------------ls -This command lists the files and subdirectories in a directory. If you simply type "ls", it will display the files in your current directory. You can also specify the pathname of another directory, and it will display the files in it. It will not display hidden files (files whose name begins with a period). Options: a -This option will display all files, including hidden files. Example: $ ls -a . .. junk source $cd -This is the command used to move from one directory to another. To go to a directory directly below your current directory, type "cd <dirname>". To move up to the directory directly above your current directory, type "cd .." You can also jump to any directory in the system from any other directory in the system by specifying the path- name of the directory you wish to go to, such as "cd /usr/source". Example: $cd /usr/source $pwd -This prints out the pathname of the directory you are currently in. Useful if you forget where you're at in the system tree. Example: $pwd /usr/sourcecat -Displays the contents of a text file on the screen. The correct syntax is "cat <filename>". You can use basenames or pathnames. Example: $cat memo Bill, Remember to feed the cat! -Martha
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -