📄 csh.2
字号:
and then put in the background using.I bg.Some time later when the `s' command was finished,.I edtried to read another command and was stopped because jobsin the backgound cannot read from the terminal. The.I fgcommand returned the `ed' job to the foreground where it could once againaccept commands from the terminal..PPThe command.DSstty tostop.DEcauses all background jobs run on your terminal to stopwhen they are about towrite output to the terminal. This prevents messages from backgroundjobs from interrupting foreground job output and allows you to runa job in the background without losing terminal output. It alsocan be used for interactive programs that sometimes have longperiods without interaction. Thus each time it outputs a prompt for moreinput it will stop before the prompt. It can then be run in theforeground using.I fg,more input can be given and, if necessary stopped and returned tothe background. This.I sttycommand might be a good thing to put in your.I \&.loginfile if you do not like output from background jobs interruptingyour work. It also can reduce the need for redirecting the outputof background jobs if the output is not very big:.DS% stty tostop% wc hugefile &[1] 10387% ed text\&. . . some time laterq.ta 1.75i[1] Stopped (tty output) wc hugefile% fg wcwc hugefile 13371 30123 302577% stty \-tostop.so tabs.DEThus after some time the `wc' command, which counts the lines, wordsand characters in a file, had one line of output. When it tried towrite this to the terminal it stopped. By restarting it in theforeground we allowed it to write on the terminal exactly when we wereready to look at its output.Programs which attempt to change the mode of the terminal will alsoblock, whether or not.I tostopis set, when they are not in the foreground, asit would be very unpleasant to have a background job change the stateof the terminal..PPSince the.I jobscommand only prints jobs started in the currently executing shell,it knows nothing about background jobs started in other login sessionsor within shell files. The.I pscan be used in this case to find out about background jobs not startedin the current shell..NH 2Working Directories.PPAs mentioned in section 1.6, the shell is always in a particular.I "working directory."The `change directory' command.I chdir(itsshort form.I cdmay also be used)changes the working directory of the shell,that is, changes the directory youare located in..PPIt is useful to make a directory for each project you wish to work onand to place all files related to that project in that directory.The `make directory' command,.I mkdir,creates a new directory.The.I pwd(`print working directory') commandreports the absolute pathname of the working directory of the shell,that is, the directory you arelocated in.Thus in the example below:.DS% pwd/usr/bill% mkdir newpaper% chdir newpaper% pwd/usr/bill/newpaper%.DEthe user has created and moved to thedirectory.I newpaper.where, for example, he mightplace a group of related files..PPNo matter where you have moved to in a directory hierarchy,you can return to your `home' login directory by doing just.DScd.DEwith no arguments.The name `..' always means the directory above the current one inthe hierarchy, thus.DScd ...DEchanges the shell's working directory to the one directly above thecurrent one.The name `..' can be used in anypathname, thus,.DScd ../programs.DEmeanschange to the directory `programs' contained in the directoryabove the current one.If you have several directories for differentprojects under, say, your home directory,this shorthand notationpermits you to switch easily between them..PPThe shell always remembers the pathname of its current working directory inthe variable.I cwd.The shell can also be requested to remember the previous directory whenyou change to a new working directory. If the `push directory' command.I pushdis used in place of the.I cdcommand, the shell saves the name of the current working directoryon a.I "directory stack"before changing to the new one.You can see this list at any time by typing the `directories'command.I dirs..ID.nf% pushd newpaper/references~/newpaper/references ~% pushd /usr/lib/tmac/usr/lib/tmac ~/newpaper/references ~% dirs/usr/lib/tmac ~/newpaper/references ~% popd~/newpaper/references ~% popd~%.DEThe list is printed in a horizontal line, reading left to right,with a tilde (~) asshorthand for your home directory\(emin this case `/usr/bill'.The directory stack is printed whenever there is more than oneentry on it and it changes.It is also printed by a.I dirscommand..I Dirsis usually faster and more informative than.I pwdsince it shows the current working directory as well as anyother directories remembered in the stack..PPThe.I pushdcommand with no argumentalternates the current directory with the first directory in thelist.The `pop directory'.I popdcommand without an argument returns you to the directory you were in prior tothe current one, discarding the previous current directory from thestack (forgetting it).Typing.I popdseveral times in a series takes you backward through the directoriesyou had been in (changed to) by.I pushdcommand.There are other options to.I pushdand.I popdto manipulate the contents of the directory stack and to changeto directories not at the top of the stack; see the.I cshmanual page for details..PPSince the shell remembers the working directory in which each jobwas started, it warns you when you might be confused by restartinga job in the foreground which has a different working directory than thecurrent working directory of the shell. Thus if you start a backgroundjob, then change the shell's working directory and then cause thebackground job to run in the foreground, the shell warns you that theworking directory of the currently running foreground job is differentfrom that of the shell..DS% dirs \-l/mnt/bill% cd myproject% dirs~/myproject% ed prog.c1143^ZStopped% cd ..% lsmyprojecttextfile% fged prog.c (wd: ~/myproject).DEThis way the shell warns you when thereis an implied change of working directory, even though no cd command wasissued. In the above example the `ed' job was still in `/mnt/bill/project'even though the shell had changed to `/mnt/bill'.A similar warning is given when such a foreground jobterminates or is suspended (using the \s-2STOP\s0 signal) sincethe return to the shell again implies a change of working directory..DS% fged prog.c (wd: ~/myproject) . . . after some editingq(wd now: ~)%.DEThese messages are sometimes confusing if you use programs that changetheir own working directories, since the shell only remembers whichdirectory a job is started in, and assumes it stays there.The `\-l' option of.I jobswill type the working directoryof suspended or background jobs when it is differentfrom the current working directory of the shell..NH 2Useful built-in commands.PPWe now give a few of the useful built-in commands of the shell describinghow they are used..PPThe.I aliascommand described above is used to assign new aliases and to show theexisting aliases.With no arguments it prints the current aliases.It may also be given only one argument such as.DSalias ls.DEto show the current alias for, e.g., `ls'..PPThe.I echocommand prints its arguments.It is often used in.I "shell scripts"or as an interactive commandto see what filename expansions will produce..PPThe.I historycommand will show the contents of the history list.The numbers given with the history events can be used to referenceprevious events which are difficult to reference using thecontextual mechanisms introduced above.There is also a shell variable called.I prompt.By placing a `!' character in its value the shell will there substitutethe number of the current command in the history list.You can use this number to refer to this command in a history substitution.Thus you could.DSset prompt=\'\e! % \'.DENote that the `!' character had to be.I escapedhere even within `\'' characters..PPThe.I limitcommand is used to restrict use of resources.With no arguments it prints the current limitations:.DS.ta 1icputime unlimitedfilesize unlimiteddatasize 5616 kbytesstacksize 512 kbytescoredumpsize unlimited.so tabs.DELimits can be set, e.g.:.DSlimit coredumpsize 128k.DEMost reasonable units abbreviations will work; see the.I cshmanual page for more details..PPThe.I logoutcommand can be used to terminate a login shell which has.I ignoreeofset..PPThe.I rehashcommand causes the shell to recompute a table of where commands arelocated. This is necessary if you add a command to a directoryin the current shell's search path and wish the shell to find it,since otherwise the hashing algorithm may tell the shell that thecommand wasn't in that directory when the hash table was computed..PPThe.I repeatcommand can be used to repeat a command several times.Thus to make 5 copies of the file.I onein the file.I fiveyou could do.DSrepeat 5 cat one >> five.DE.PPThe.I setenvcommand can be usedto set variables in the environment.Thus.DSsetenv TERM adm3a.DEwill set the value of the environment variable \s-2TERM\s0to`adm3a'.A user program.I printenvexists which will print out the environment.It might then show:.DS% printenvHOME=/usr/billSHELL=/bin/cshPATH=:/usr/ucb:/bin:/usr/bin:/usr/localTERM=adm3aUSER=bill%.DE.PPThe.I sourcecommand can be used to force the current shell to read commands froma file.Thus.DSsource .cshrc.DEcan be used after editing in a change to the.I \&.cshrcfile which you wish to take effect right away..PPThe.I timecommand can be used to cause a command to be timed no matter how much\s-2CPU\s0 time it takes.Thus.DS% time cp /etc/rc /usr/bill/rc0.0u 0.1s 0:01 8% 2+1k 3+2io 1pf+0w% time wc /etc/rc /usr/bill/rc 52 178 1347 /etc/rc 52 178 1347 /usr/bill/rc 104 356 2694 total0.1u 0.1s 0:00 13% 3+3k 5+3io 7pf+0w%.DEindicates that the.I cpcommand used a negligible amount of user time (u)and about 1/10th of a system time (s); the elapsed time was 1 second (0:01),there was an average memory usage of 2k bytes of program space and 1kbytes of data space over the cpu time involved (2+1k); the programdid three disk reads and two disk writes (3+2io), and took one page faultand was not swapped (1pf+0w).The word count command.I wcon the other hand used 0.1 seconds of user time and 0.1 seconds of systemtime in less than a second of elapsed time.The percentage `13%' indicates that over the period when it was activethe command `wc' used an average of 13 percent of the available \s-2CPU\s0cycles of the machine..PPThe.I unaliasand.I unsetcommands can be usedto remove aliases and variable definitions from the shell, and.I unsetenvremoves variables from the environment..NH 2What else?.PPThis concludes the basic discussion of the shell for terminal users.There are more features of the shell to be discussed here, and allfeatures of the shell are discussed in its manual pages.One useful feature which is discussed later is the.I foreachbuilt-in command which can be used to run the same commandsequence with a number of different arguments..PPIf you intend to use \s-2UNIX\s0 a lot you you should look throughthe rest of this document and the csh manual pages (section1) to become familiarwith the other facilities which are available to you..bp
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -