📄 csh.1
字号:
If it had existed previously these previous contents would have been discarded!A shell option.I noclobberexists to prevent this from happening accidentally;it is discussed in section 2.2..PPThe system normally keeps files which you create with `>' and all other files.Thus the default is for files to be permanent. If you wish to create a filewhich will be removed automatically, you can begin its name with a `#'character, this `scratch' character denotes the fact that the file willbe a scratch file.*.FS*Note that if your erase character is a `#', you will have to precede the`#' with a `\e'. The fact that the `#' character is the old (pre-\s-2CRT\s0)standard erase character means that it seldom appears in a file name, andallows this convention to be used for scratch files. If you are using a\s-2CRT\s0, your erase character should be a ^H, as we demonstratedin section 1.1 how this could be set up..FEThe system will remove such files after a couple of days,or sooner if file space becomes very tight.Thus, in running the.I datecommand above, we don't really want to save the output forever, so wewould more likely do.DSdate > #now.DE.NH 2Metacharacters in the shell.PPThe shell has a large number ofspecial characters (like `>')which indicate special functions.We say that these notations have.I syntacticand.I semanticmeaning to the shell.In general, most characters which are neither letters nor digitshave special meaning to the shell.We shall shortly learn a means of.I quotationwhich allows us to use.I metacharacterswithout the shell treating them in any special way..PPMetacharacters normally have effect only when the shell is readingour input.We need not worry about placing shell metacharacters in a letterwe are sending via.I mail,or when we are typing in text or data to some other program.Note that the shell is only reading input when it has prompted with`% ' (although we can type our input even before it prompts)..NH 2Input from files; pipelines.PPWe learned above how to.I redirectthe.I "standard output"of a commandto a file.It is also possible to redirect the.I "standard input"of a command from a file.This is not often necessary since most commands will read froma file whose name is given as an argument.We can give the command.DSsort < data.DEto run the.I sortcommand with standard input, where the command normallyreads its input, from the file`data'.We would more likely say.DSsort data.DEletting the.I sortcommand open the file`data'for input itself since this is less to type..PPWe should note that if we just typed.DSsort.DEthen the sort program would sort lines from its.I "standard input."Since we did not.I redirectthe standard input, it would sort lines as we typed them on the terminaluntil we typed a ^D to indicate an end-of-file..PPA most useful capability is the ability to combine the standard outputof one command with the standard input of another, i.e. to run thecommands in a sequence known as a.I pipeline.For instance the command.DSls \-s.DEnormally produces a list of the files in our directory with the sizeof each in blocks of 512 characters.If we are interested in learning which of our files is largest wemay wish to have this sorted by size rather than by name, which isthe default way in which.I lssorts.We could look at the many options of.I lsto see if there was an option to do this but would eventually discoverthat there is not.Instead we can use a couple of simple options of the.I sortcommand, combining it with.I lsto get what we want..PPThe.I \-noption of sort specifies a numeric sort rather than an alphabetic sort.Thus.DSls \-s | sort \-n.DEspecifies that the output of the.I lscommand run with the option.I \-sis to be.I pipedto the command.I sortrun with the numeric sort option.This would give us a sorted list of our files by size, but with thesmallest first.We could then use the.I \-rreverse sort option and the.I headcommand in combination with the previous command doing.DSls \-s | sort \-n \-r | head \-5.DEHere we have taken a list of our files sorted alphabetically,each with the size in blocks.We have run this to the standard input of the.I sortcommand asking it to sort numerically in reverse order (largest first).This output has then been run into the command.I headwhich gives us the first few lines.In this case we have asked.I headfor the first 5 lines.Thus this command gives us the names and sizes of our 5 largest files..PPThe notation introduced above is called the.I pipemechanism.Commands separated by `\||\|' characters are connected together by theshell and the standard output of each is run into the standard input of thenext.The leftmost command in a pipeline will normally take its standardinput from the terminal and the rightmost will place its standardoutput on the terminal.Other examples of pipelines will be given later when we discuss thehistory mechanism;one important use of pipes which is illustrated there is in therouting of information to the line printer..NH 2Filenames.PPMany commands to be executed will need the names of files as arguments.\s-2UNIX\s0.I pathnamesconsist of a number of.I componentsseparated by `/'.Each component except the last names a directory in which the nextcomponent resides, in effect specifying the.I pathof directories to follow to reach the file.Thus the pathname.DS/etc/motd.DEspecifies a file in the directory`etc'which is a subdirectory of the.I rootdirectory `/'.Within this directory the file named is `motd' which standsfor `message of the day'.A.I pathnamethat begins with a slash is said to be an.I absolutepathname since it is specified from the absolute top of the entiredirectory hierarchy of the system (the.I root )..I Pathnameswhich do not begin with `/' are interpreted as starting in the current.I "working directory" ,which is, by default, your.I homedirectory and can be changed dynamically by the.I cdchange directory command.Such pathnames are said to be.I relativeto the working directory since they are found by startingin the working directory and descending to lower levels of directoriesfor each.I componentof the pathname. If the pathname contains no slashes at all then thefile is contained in the working directory itself and the pathname is merelythe name of the file in this directory.Absolute pathnames have no relationto the working directory..PPMost filenames consist of a number of alphanumeric characters and`.'s (periods).In fact, all printing characters except `/' (slash) may appear in filenames.It is inconvenient to have most non-alphabetic characters in filenamesbecause many of these have special meaning to the shell.The character `.' (period) is not a shell-metacharacter and is often usedto separate the.I extensionof a file name from the base of the name.Thus.DSprog.c prog.o prog.errs prog.output.DEare four related files.They share a.I baseportion of a name(a base portion being that part of the name that is left when a trailing`.' and following characters which are not `.' are stripped off).The file`prog.c'might be the source for a C program,the file `prog.o' the corresponding object file,the file`prog.errs' the errors resulting from a compilation of the programand the file`prog.output' the output of a run of the program..PPIf we wished to refer to all four of these files in a command, we coulduse the notation.DSprog.*.DEThis expression is expanded by the shell, before the command to which it isan argument is executed, into a list of names which begin with `prog.'.The character `*' here matches any sequence (including the empty sequence)of characters in a file name.The names which match are alphabetically sorted and placed in the.I "argument list"of the command.Thus the command.DSecho prog.*.DEwill echo the names.DSprog.c prog.errs prog.o prog.output.DENote that the names are in sorted order here, and a differentorder than we listed them above.The.I echocommand receives four words as arguments, even though we only typedone word as as argument directly.The four words were generated by.I "filename expansion"of the one input word..PPOther notations for.I "filename expansion"are also available.The character `?' matches any single character in a filename.Thus.DSecho ? \|?? \|???.DEwill echo a line of filenames; first those with one character names,then those with two character names, and finally those with threecharacter names.The names of each length will be independently sorted..PPAnother mechanism consists of a sequence of characters between `[' and `]'.This metasequence matches any single character from the enclosed set.Thus.DSprog.[co].DEwill match.DSprog.c prog.o.DEin the example above.We can also place two characters around a `\-' in this notation to denotea range.Thus.DSchap.[1\-5].DEmight match files.DSchap.1 chap.2 chap.3 chap.4 chap.5.DEif they existed.This is shorthand for.DSchap.[12345].DEand otherwise equivalent..PPAn important point to note is that if a list of argument words toa command (an.I "argument list)"contains filename expansion syntax, and if this filename expansion syntaxfails to match any existing file names, then the shell considers thisto be an error and prints a diagnostic.DSNo match..DEand does not execute the command..PPAnother very important point is that files with the character `.' at the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -