BSD 4_3 release
[unix-history] / usr / doc / usd / 01.begin / u2
CommitLineData
95f51977 1.\" @(#)u2 6.1 (Berkeley) 5/22/86
fc2a7a49
KD
2.\"
3.SH
4II. DAY-TO-DAY USE
5.SH
6Creating Files \(em The Editor
7.PP
8If you have to type a paper or a letter or a program,
9how do you get the information stored in the machine?
10Most of these tasks are done with
11the
12.UC UNIX
13``text editor''
14.UL ed .
15Since
16.UL ed
17is thoroughly documented in
18.UL ed (1)
19and explained in
20.ul
21A Tutorial Introduction to the UNIX Text Editor,
22we won't spend any time here describing how to use it.
23All we want it for right now is to make some
24.ul
25files.
26(A file is just a collection of information stored in the machine,
27a simplistic but adequate definition.)
28.PP
29To create a file
30called
31.UL junk
32with some text in it, do the following:
33.P1
34.ta .65i
35ed junk \fR(invokes the text editor)\f3
36a \fR(command to ``ed'', to add text)\f3
37.ft I
38now type in
39whatever text you want ...
40.ft 3
41\&. \fR(signals the end of adding text)\f3
42.P2
43The ``\f3.\fR'' that signals the end of adding text must be
44at the beginning of a line by itself.
45Don't forget it,
46for until it is typed,
47no other
48.UL ed
49commands will be recognized \(em
50everything you type will be treated as text to be added.
51.PP
52At this point you can do various editing operations
53on the text you typed in, such as correcting spelling mistakes,
54rearranging paragraphs and the like.
55Finally, you must write the information you have typed
56into a file with the editor command
57.UL w :
58.P1
59w
60.P2
61.UL ed
62will respond with the number of characters it wrote
63into the file
64.UL junk .
65.PP
66Until the
67.UL w
68command,
69nothing is stored permanently,
70so if you hang up and go home
71the information is lost.\(dg
72.FS
73\(dg This is not strictly true \(em
74if you hang up while editing, the data you were
75working on is saved in a file called
76.UL ed.hup ,
77which you can continue with at your next session.
78.FE
79But after
80.UL w
81the information is there permanently;
82you can re-access it any time by typing
83.P1
84ed junk
85.P2
86Type a
87.UL q
88command
89to quit the editor.
90(If you try to quit without writing,
91.UL ed
92will print a
93.UL ?
94to remind you.
95A second
96.UL q
97gets you out regardless.)
98.PP
99Now create a second file called
100.UL temp
101in the same manner.
102You should now have two files,
103.UL junk
104and
105.UL temp .
106.SH
107What files are out there?
108.PP
109The
110.UL ls
111(for ``list'') command lists the names
112(not contents)
113of any of the files that
114.UC UNIX
115knows about.
116If you type
117.P1
118ls
119.P2
120the response will be
121.P1
122junk
123temp
124.P2
125which are indeed the two files just created.
126The names are sorted into alphabetical order automatically,
127but other variations are possible.
128For example,
129the command
130.P1
131ls -t
132.P2
133causes the files to be listed in the order in which they were last changed,
134most recent first.
135The
136.UL \-l
137option gives a ``long'' listing:
138.P1
139ls -l
140.P2
141will produce something like
142.P1
143-rw-rw-rw- 1 bwk 41 Jul 22 2:56 junk
144-rw-rw-rw- 1 bwk 78 Jul 22 2:57 temp
145.P2
146The date and time are of the last change to the file.
147The 41 and 78 are the number of characters
148(which should agree with the numbers you got from
149.UL ed ).
150.UL bwk
151is the owner of the file, that is, the person
152who created it.
153The
154.UL \-rw\-rw\-rw\-
155tells who has permission to read and write the file,
156in this case everyone.
157.PP
158Options can be combined:
159.UL ls\ \-lt
160gives the same thing as
161.UL ls\ \-l ,
162but sorted into time order.
163You can also name the files you're interested in,
164and
165.UL ls
166will list the information about them only.
167More details can be found in
168.UL ls (1).
169.PP
170The use of optional arguments that begin with a minus sign,
171like
172.UL \-t
173and
174.UL \-lt ,
175is a common convention for
176.UC UNIX
177programs.
178In general, if a program accepts such optional arguments,
179they precede any filename arguments.
180It is also vital that you separate the various arguments with spaces:
181.UL ls\-l
182is not the same as
183.UL ls\ \ \-l .
184.SH
185Printing Files
186.PP
187Now that you've got a file of text,
188how do you print it so people can look at it?
189There are a host of programs that do that,
190probably more than are needed.
191.PP
192One simple thing is to use the editor,
193since printing is often done just before making changes anyway.
194You can say
195.P1
196ed junk
1971,$p
198.P2
199.UL ed
200will reply with the count of the characters in
201.UL junk
202and then print all the lines in the file.
203After you learn how to use the editor,
204you can be selective about the parts you print.
205.PP
206There are times when it's not feasible to use the editor for printing.
207For example, there is a limit on how big a file
208.UL ed
209can handle
210(several thousand lines).
211Secondly,
212it
213will only print one file at a time,
214and sometimes you want to print several, one after another.
215So here are a couple of alternatives.
216.PP
217First is
218.UL cat ,
219the simplest of all the printing programs.
220.UL cat
221simply prints on the terminal the contents of all the files
222named in a list.
223Thus
224.P1
225cat junk
226.P2
227prints one file, and
228.P1
229cat junk temp
230.P2
231prints two.
232The files are simply concatenated (hence the name
233.UL cat '') ``
234onto the terminal.
235.PP
236.UL pr
237produces formatted printouts of files.
238As with
239.UL cat ,
240.UL pr
241prints all the files named in a list.
242The difference is that it produces
243headings with date, time, page number and file name
244at the top of each page,
245and
246extra lines to skip over the fold in the paper.
247Thus,
248.P1
249pr junk temp
250.P2
251will print
252.UL junk
253neatly,
254then skip to the top of a new page and print
255.UL temp
256neatly.
257.PP
258.UL pr
259can also produce multi-column output:
260.P1
261pr -3 junk
262.P2
263prints
264.UL junk
265in 3-column format.
266You can use any reasonable number in place of ``3''
267and
268.UL pr
269will do its best.
270.UL pr
271has other capabilities as well;
272see
273.UL pr (1).
274.PP
275It should be noted that
276.UL pr
277is
278.ul
279not
280a formatting program in the sense of shuffling lines around
281and justifying margins.
282The true formatters are
283.UL nroff
284and
285.UL troff ,
286which we will get to in the section on document preparation.
287.PP
288There are also programs that print files
289on a high-speed printer.
290Look in your manual under
291.UL opr
292and
293.UL lpr .
294Which to use depends on
295what equipment is attached to your machine.
296.SH
297Shuffling Files About
298.PP
299Now that you have some files in the file system
300and some experience in printing them,
301you can try bigger things.
302For example,
303you can move a file from one place to another
304(which amounts to giving it a new name),
305like this:
306.P1
307mv junk precious
308.P2
309This means that what used to be ``junk'' is now ``precious''.
310If you do an
311.UL ls
312command now,
313you will get
314.P1
315precious
316temp
317.P2
318Beware that if you move a file to another one
319that already exists,
320the already existing contents are lost forever.
321.PP
322If you want
323to make a
324.ul
325copy
326of a file (that is, to have two versions of something),
327you can use the
328.UL cp
329command:
330.P1
331cp precious temp1
332.P2
333makes a duplicate copy of
334.UL precious
335in
336.UL temp1 .
337.PP
338Finally, when you get tired of creating and moving
339files,
340there is a command to remove files from the file system,
341called
342.UL rm .
343.P1
344rm temp temp1
345.P2
346will remove both of the files named.
347.PP
348You will get a warning message if one of the named files wasn't there,
349but otherwise
350.UL rm ,
351like most
352.UC UNIX
353commands,
354does its work silently.
355There is no prompting or chatter,
356and error messages are occasionally curt.
357This terseness is sometimes disconcerting
358to new\%comers,
359but experienced users find it desirable.
360.SH
361What's in a Filename
362.PP
363So far we have used filenames without ever saying what's
364a legal name,
365so it's time for a couple of rules.
366First, filenames are limited to 14 characters,
7f5db720
KD
367which is enough to be descriptive.\(dg
368.FS
369\(dg In 4.2 BSD the limit was extended to 255 characters.
370.FE
fc2a7a49
KD
371Second, although you can use almost any character
372in a filename,
373common sense says you should stick to ones that are visible,
374and that you should probably avoid characters that might be used
375with other meanings.
376We have already seen, for example,
377that in the
378.UL ls
379command,
380.UL ls\ \-t
381means to list in time order.
382So if you had a file whose name
383was
384.UL \-t ,
385you would have a tough time listing it by name.
386Besides the minus sign, there are other characters which
387have special meaning.
388To avoid pitfalls,
389you would do well to
390use only letters, numbers and the period
391until you're familiar with the situation.
392.PP
393On to some more positive suggestions.
394Suppose you're typing a large document
395like a book.
396Logically this divides into many small pieces,
397like chapters and perhaps sections.
398Physically it must be divided too,
399for
400.UL ed
401will not handle really big files.
402Thus you should type the document as a number of files.
403You might have a separate file for each chapter,
404called
405.P1
406chap1
407chap2
408.ft R
409etc...
410.P2
411Or, if each chapter were broken into several files, you might have
412.P1
413chap1.1
414chap1.2
415chap1.3
416\&...
417chap2.1
418chap2.2
419\&...
420.P2
421You can now tell at a glance where a particular file fits into the whole.
422.PP
423There are advantages to a systematic naming convention which are not obvious
424to the novice
425.UC UNIX
426user.
427What if you wanted to print the whole book?
428You could say
429.P1
430pr chap1.1 chap1.2 chap1.3 ......
431.P2
432but you would get tired pretty fast, and would probably even make mistakes.
433Fortunately, there is a shortcut.
434You can say
435.P1
436pr chap*
437.P2
438The
439.UL *
440means ``anything at all,''
441so this translates into ``print all files
442whose names begin with
443.UL chap '',
444listed in alphabetical order.
445.PP
446This shorthand notation
447is not a property of the
448.UL pr
449command, by the way.
450It is system-wide, a service of the program
451that interprets commands
452(the ``shell,''
453.UL sh (1)).
454Using that fact, you can see how to list the names of the files in the book:
455.P1
456ls chap*
457.P2
458produces
459.P1
460chap1.1
461chap1.2
462chap1.3
463\&...
464.P2
465The
466.UL *
467is not limited to the last position in a filename \(em
468it can be anywhere
469and can occur several times.
470Thus
471.P1
472rm *junk* *temp*
473.P2
474removes all files that contain
475.UL junk
476or
477.UL temp
478as any part of their name.
479As a special case,
480.UL *
481by itself matches every filename,
482so
483.P1
484pr *
485.P2
486prints all your files
487(alphabetical order),
488and
489.P1
490rm *
491.P2
492removes
493.ul
494all files.
495(You had better be
496.IT very
497sure that's what you wanted to say!)
498.PP
499The
500.UL *
501is not
502the only pattern-matching feature available.
503Suppose you want to print only chapters 1 through 4 and 9.
504Then you can say
505.P1
506pr chap[12349]*
507.P2
508The
509.UL [...]
510means to match any of the characters inside the brackets.
511A range of consecutive letters or digits can be abbreviated,
512so you can also do this
513with
514.P1
515pr chap[1-49]*
516.P2
517Letters can also be used within brackets:
518.UL [a\-z]
519matches any character in the range
520.UL a
521through
522.UL z .
523.PP
524The
525.UL ?
526pattern matches any single character,
527so
528.P1
529ls ?
530.P2
531lists all files which have single-character names,
532and
533.P1
534ls -l chap?.1
535.P2
536lists information about the first file of each chapter
537.UL chap1.1 \&, (
538.UL chap2.1 ,
539etc.).
540.PP
541Of these niceties,
542.UL *
543is certainly the most useful,
544and you should get used to it.
545The others are frills, but worth knowing.
546.PP
547If you should ever have to turn off the special meaning
548of
549.UL * ,
550.UL ? ,
551etc.,
552enclose the entire argument in single quotes,
553as in
554.P1
555ls \(fm?\(fm
556.P2
557We'll see some more examples of this shortly.
558.SH
559What's in a Filename, Continued
560.PP
561When you first made that file called
562.UL junk ,
563how did
564the system
565know that there wasn't another
566.UL junk
567somewhere else,
568especially since the person in the next office is also
569reading this tutorial?
570The answer is that generally each user
571has a private
572.IT directory ,
573which contains only the files that belong to him.
574When you log in, you are ``in'' your directory.
575Unless you take special action,
576when you create a new file,
577it is made in the directory that you are currently in;
578this is most often your own directory,
579and thus the file is unrelated to any other file of the same name
580that might exist in someone else's directory.
581.PP
582The set of all files
583is organized into a (usually big) tree,
584with your files located several branches into the tree.
585It is possible for you to ``walk'' around this tree,
586and to find any file in the system, by starting at the root
587of the tree and walking along the proper set of branches.
588Conversely, you can start where you are and walk toward the root.
589.PP
590Let's try the latter first.
591The basic tools is the command
592.UL pwd
593(``print working directory''),
594which prints the name of the directory you are currently in.
595.PP
596Although the details will vary according to the system you are on,
597if you give the
598command
599.UL pwd ,
600it will print something like
601.P1
602/usr/your\(hyname
603.P2
604This says that you are currently in the directory
605.UL your-name ,
606which is in turn in the directory
607.UL /usr ,
608which is in turn in the root directory
609called by convention just
610.UL / .
611(Even if it's not called
612.UL /usr
613on your system,
614you will get something analogous.
7f5db720 615Make the corresponding mental adjustment and read on.)
fc2a7a49
KD
616.PP
617If you now type
618.P1
619ls /usr/your\(hyname
620.P2
621you should get exactly the same list of file names
622as you get from a plain
623.UL ls :
624with no arguments,
625.UL ls
626lists the contents of the current directory;
627given the name of a directory,
628it lists the contents of that directory.
629.PP
630Next, try
631.P1
632ls /usr
633.P2
634This should print a long series of names,
635among which is your own login name
636.UL your-name .
637On many systems,
638.UL usr
639is a directory that contains the directories
640of all the normal users of the system,
641like you.
642.PP
643The next step is to try
644.P1
645ls /
646.P2
647You should get a response something like this
648(although again the details may be different):
649.P1
650bin
651dev
652etc
653lib
654tmp
655usr
656.P2
657This is a collection of the basic directories of files
658that
659the system
660knows about;
661we are at the root of the tree.
662.PP
663Now try
664.P1
665cat /usr/your\(hyname/junk
666.P2
667(if
668.UL junk
669is still around in your directory).
670The name
671.P1
672/usr/your\(hyname/junk
673.P2
674is called the
675.UL pathname
676of the file that
677you normally think of as ``junk''.
678``Pathname'' has an obvious meaning:
679it represents the full name of the path you have to follow from the root
680through the tree of directories to get to a particular file.
681It is a universal rule in
682the
683.UC UNIX
684system
685that anywhere you can use an ordinary filename,
686you can use a pathname.
687.PP
688Here is a picture which may make this clearer:
689.P1 1
690.ft R
691.if t .vs 9p
692.if t .tr /\(sl
693.if t .tr ||
694.ce 100
695(root)
696/ | \e
697/ | \e
698/ | \e
699 bin etc usr dev tmp
700/ | \e / | \e / | \e / | \e / | \e
701/ | \e
702/ | \e
703adam eve mary
704/ / \e \e
705 / \e junk
706junk temp
707.ce 0
708.br
709.tr //
710.P2
711.LP
712Notice that Mary's
713.UL junk
714is unrelated to Eve's.
715.PP
716This isn't too exciting if all the files of interest are in your own
717directory, but if you work with someone else
718or on several projects concurrently,
719it becomes handy indeed.
720For example, your friends can print your book by saying
721.P1
722pr /usr/your\(hyname/chap*
723.P2
724Similarly, you can find out what files your neighbor has
725by saying
726.P1
727ls /usr/neighbor\(hyname
728.P2
729or make your own copy of one of his files by
730.P1
731cp /usr/your\(hyneighbor/his\(hyfile yourfile
732.P2
733.PP
734If your neighbor doesn't want you poking around in his files,
735or vice versa,
736privacy can be arranged.
737Each file and directory has read-write-execute permissions for the owner,
738a group, and everyone else,
739which can be set
740to control access.
741See
742.UL ls (1)
743and
744.UL chmod (1)
745for details.
746As a matter of observed fact,
747most users most of the time find openness of more
748benefit than privacy.
749.PP
750As a final experiment with pathnames, try
751.P1
752ls /bin /usr/bin
753.P2
754Do some of the names look familiar?
755When you run a program, by typing its name after the prompt character,
756the system simply looks for a file of that name.
757It normally looks first in your directory
758(where it typically doesn't find it),
759then in
760.UL /bin
761and finally in
762.UL /usr/bin .
763There is nothing magic about commands like
764.UL cat
765or
766.UL ls ,
767except that they have been collected into a couple of places to be easy to find and administer.
768.PP
769What if you work regularly with someone else on common information
770in his directory?
771You could just log in as your friend each time you want to,
772but you can also say
773``I want to work on his files instead of my own''.
774This is done by changing the directory that you are
775currently in:
776.P1
777cd /usr/your\(hyfriend
778.P2
779(On some systems,
780.UL cd
781is spelled
782.UL chdir .)
783Now when you use a filename in something like
784.UL cat
785or
786.UL pr ,
787it refers to the file in your friend's directory.
788Changing directories doesn't affect any permissions associated
789with a file \(em
790if you couldn't access a file from your own directory,
791changing to another directory won't alter that fact.
792Of course,
793if you forget what directory you're in, type
794.P1
795pwd
796.P2
797to find out.
798.PP
799It is usually convenient to arrange your own files
800so that all the files related to one thing are in a directory separate
801from other projects.
802For example, when you write your book, you might want to keep all the text
803in a directory called
804.UL book .
805So make one with
806.P1
807mkdir book
808.P2
809then go to it with
810.P1
811cd book
812.P2
813then start typing chapters.
814The book is now found in (presumably)
815.P1
816/usr/your\(hyname/book
817.P2
818To remove the directory
819.UL book ,
820type
821.P1
822rm book/*
823rmdir book
824.P2
825The first command removes all files from the directory;
826the second
827removes the empty directory.
828.PP
829You can go up one level in the tree of files
830by saying
831.P1
832cd ..
833.P2
834.UL .. '' ``
835is the name of the parent of whatever directory you are currently in.
836For completeness,
837.UL . '' ``
838is an alternate name
839for the directory you are in.
840.SH
841Using Files instead of the Terminal
842.PP
843Most of the commands we have seen so far produce output
844on the terminal;
845some, like the editor, also take their input from the terminal.
846It is universal in
847.UC UNIX
848systems
849that the terminal can be replaced by a file
850for either or both of input and output.
851As one example,
852.P1
853ls
854.P2
855makes a list of files on your terminal.
856But if you say
857.P1
858ls >filelist
859.P2
860a list of your files will be placed in the file
861.UL filelist
862(which
863will be created if it doesn't already exist,
864or overwritten if it does).
865The symbol
866.UL >
867means ``put the output on the following file,
868rather than on the terminal.''
869Nothing is produced on the terminal.
870As another example, you could combine
871several files into one by capturing the output of
872.UL cat
873in a file:
874.P1
875cat f1 f2 f3 >temp
876.P2
877.PP
878The symbol
879.UL >>
880operates very much like
881.UL >
882does,
883except that it means
884``add to the end of.''
885That is,
886.P1
887cat f1 f2 f3 >>temp
888.P2
889means to concatenate
890.UL f1 ,
891.UL f2
892and
893.UL f3
894to the end of whatever is already in
895.UL temp ,
896instead of overwriting the existing contents.
897As with
898.UL > ,
899if
900.UL temp
901doesn't exist, it will be created for you.
902.PP
903In a similar way, the symbol
904.UL <
905means to take the input
906for a program from the following file,
907instead of from the terminal.
908Thus, you could make up a script of commonly used editing commands
909and put them into a file called
910.UL script .
911Then you can run the script on a file by saying
912.P1
913ed file <script
914.P2
915As another example, you can use
916.UL ed
917to prepare a letter in file
918.UL let ,
919then send it to several people with
920.P1
921mail adam eve mary joe <let
922.P2
923.SH
924Pipes
925.PP
926One of the novel contributions of
927the
928.UC UNIX
929system
930is the idea of a
931.ul
932pipe.
933A pipe is simply a way to connect the output of one program
934to the input of another program,
935so the two run as a sequence of processes \(em
936a pipeline.
937.PP
938For example,
939.P1
940pr f g h
941.P2
942will print the files
943.UL f ,
944.UL g ,
945and
946.UL h ,
947beginning each on a new page.
948Suppose you want
949them run together instead.
950You could say
951.P1
952cat f g h >temp
953pr <temp
954rm temp
955.P2
956but this is more work than necessary.
957Clearly what we want is to take the output of
958.UL cat
959and
960connect it to the input of
961.UL pr .
962So let us use a pipe:
963.P1
964cat f g h | pr
965.P2
966The vertical bar
967.UL |
968means to
969take the output from
970.UL cat ,
971which would normally have gone to the terminal,
972and put it into
973.UL pr
974to be neatly formatted.
975.PP
976There are many other examples of pipes.
977For example,
978.P1
979ls | pr -3
980.P2
981prints a list of your files in three columns.
982The program
983.UL wc
984counts the number of lines, words and characters in
985its input, and as we saw earlier,
986.UL who
987prints a list of currently-logged on people,
988one per line.
989Thus
990.P1
991who | wc
992.P2
993tells how many people are logged on.
994And of course
995.P1
996ls | wc
997.P2
998counts your files.
999.PP
1000Any program
1001that reads from the terminal
1002can read from a pipe instead;
1003any program that writes on the terminal can drive
1004a pipe.
1005You can have as many elements in a pipeline as you wish.
1006.PP
1007Many
1008.UC UNIX
1009programs are written so that they will take their input from one or more files
1010if file arguments are given;
1011if no arguments are given they will read from the terminal,
1012and thus can be used in pipelines.
1013.UL pr
1014is one example:
1015.P1
1016pr -3 a b c
1017.P2
1018prints files
1019.UL a ,
1020.UL b
1021and
1022.UL c
1023in order in three columns.
1024But in
1025.P1
1026cat a b c | pr -3
1027.P2
1028.UL pr
1029prints the information coming down the pipeline,
1030still in
1031three columns.
1032.SH
1033The Shell
1034.PP
1035We have already mentioned once or twice the mysterious
1036``shell,''
1037which is in fact
7f5db720
KD
1038.UL sh (1).\(dg
1039.FS
1040\(dg On Berkeley Unix systems, the usual shell for interactive use is the c shell,
1041.UL csh(1).
1042.FE
fc2a7a49
KD
1043The shell is the program that interprets what you type as
1044commands and arguments.
1045It also looks after translating
1046.UL * ,
1047etc.,
1048into lists of filenames,
1049and
1050.UL < ,
1051.UL > ,
1052and
1053.UL |
1054into changes of input and output streams.
1055.PP
1056The shell has other capabilities too.
1057For example, you can run two programs with one command line
1058by separating the commands with a semicolon;
1059the shell recognizes the semicolon and
1060breaks the line into two commands.
1061Thus
1062.P1
1063date; who
1064.P2
1065does both commands before returning with a prompt character.
1066.PP
1067You can also have more than one program running
1068.ul
1069simultaneously
1070if you wish.
1071For example, if you are doing something time-consuming,
1072like the editor script
1073of an earlier section,
1074and you don't want to wait around for the results before starting something else,
1075you can say
1076.P1
1077ed file <script &
1078.P2
1079The ampersand at the end of a command line
1080says ``start this command running,
1081then take further commands from the terminal immediately,''
1082that is,
1083don't wait for it to complete.
1084Thus the script will begin,
1085but you can do something else at the same time.
1086Of course, to keep the output from interfering
1087with what you're doing on the terminal,
1088it would be better to say
1089.P1
1090ed file <script >script.out &
1091.P2
1092which saves the output lines in a file
1093called
1094.UL script.out .
1095.PP
1096When you initiate a command with
1097.UL & ,
1098the system
1099replies with a number
1100called the process number,
1101which identifies the command in case you later want
1102to stop it.
1103If you do, you can say
1104.P1
1105kill process\(hynumber
1106.P2
1107If you forget the process number,
1108the command
1109.UL ps
1110will tell you about everything you have running.
1111(If you are desperate,
1112.UL kill\ 0
1113will kill all your processes.)
1114And if you're curious about other people,
1115.UL ps\ a
1116will tell you about
1117.ul
1118all
1119programs that are currently running.
1120.PP
1121You can say
1122.P1 1
1123(command\(hy1; command\(hy2; command\(hy3) &
1124.P2
1125to start three commands in the background,
1126or you can start a background pipeline with
1127.P1
1128command\(hy1 | command\(hy2 &
1129.P2
1130.PP
1131Just as you can tell the editor
1132or some similar program to take its input
1133from a file instead of from the terminal,
1134you can tell the shell to read a file
1135to get commands.
1136(Why not? The shell, after all, is just a program,
1137albeit a clever one.)
1138For instance, suppose you want to set tabs on
1139your terminal, and find out the date
1140and who's on the system every time you log in.
1141Then you can put the three necessary commands
1142.UL tabs , (
1143.UL date ,
1144.UL who )
1145into a file, let's call it
1146.UL startup ,
1147and then run it with
1148.P1
1149sh startup
1150.P2
1151This says to run the shell with the file
1152.UL startup
1153as input.
1154The effect is as if you had typed
1155the contents of
1156.UL startup
1157on the terminal.
1158.PP
1159If this is to be a regular thing,
1160you can eliminate the
1161need to type
1162.UL sh :
1163simply type, once only, the command
1164.P1
1165chmod +x startup
1166.P2
1167and thereafter you need only say
1168.P1
1169startup
1170.P2
1171to run the sequence of commands.
1172The
1173.UL chmod (1)
1174command marks the file executable;
1175the shell recognizes this and runs it as a sequence of commands.
1176.PP
1177If you want
1178.UL startup
1179to run automatically every time you log in,
1180create a file in your login directory called
1181.UL .profile ,
1182and place in it the line
1183.UL startup .
1184When the shell first gains control when you log in,
1185it looks for the
1186.UL .profile
7f5db720
KD
1187file and does whatever commands it finds in it.\(dg
1188.FS
1189\(dg The c shell instead reads a file called
1190.UL .login
1191.
1192.FE
fc2a7a49
KD
1193We'll get back to the shell in the section
1194on programming.