document distributed with 4.1BSD
[unix-history] / usr / src / share / doc / usd / 01.begin / u2
CommitLineData
fc2a7a49
KD
1.\" @(#)u2 4.1 (Berkeley) %G%
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,
367which is enough to be descriptive.
368Second, although you can use almost any character
369in a filename,
370common sense says you should stick to ones that are visible,
371and that you should probably avoid characters that might be used
372with other meanings.
373We have already seen, for example,
374that in the
375.UL ls
376command,
377.UL ls\ \-t
378means to list in time order.
379So if you had a file whose name
380was
381.UL \-t ,
382you would have a tough time listing it by name.
383Besides the minus sign, there are other characters which
384have special meaning.
385To avoid pitfalls,
386you would do well to
387use only letters, numbers and the period
388until you're familiar with the situation.
389.PP
390On to some more positive suggestions.
391Suppose you're typing a large document
392like a book.
393Logically this divides into many small pieces,
394like chapters and perhaps sections.
395Physically it must be divided too,
396for
397.UL ed
398will not handle really big files.
399Thus you should type the document as a number of files.
400You might have a separate file for each chapter,
401called
402.P1
403chap1
404chap2
405.ft R
406etc...
407.P2
408Or, if each chapter were broken into several files, you might have
409.P1
410chap1.1
411chap1.2
412chap1.3
413\&...
414chap2.1
415chap2.2
416\&...
417.P2
418You can now tell at a glance where a particular file fits into the whole.
419.PP
420There are advantages to a systematic naming convention which are not obvious
421to the novice
422.UC UNIX
423user.
424What if you wanted to print the whole book?
425You could say
426.P1
427pr chap1.1 chap1.2 chap1.3 ......
428.P2
429but you would get tired pretty fast, and would probably even make mistakes.
430Fortunately, there is a shortcut.
431You can say
432.P1
433pr chap*
434.P2
435The
436.UL *
437means ``anything at all,''
438so this translates into ``print all files
439whose names begin with
440.UL chap '',
441listed in alphabetical order.
442.PP
443This shorthand notation
444is not a property of the
445.UL pr
446command, by the way.
447It is system-wide, a service of the program
448that interprets commands
449(the ``shell,''
450.UL sh (1)).
451Using that fact, you can see how to list the names of the files in the book:
452.P1
453ls chap*
454.P2
455produces
456.P1
457chap1.1
458chap1.2
459chap1.3
460\&...
461.P2
462The
463.UL *
464is not limited to the last position in a filename \(em
465it can be anywhere
466and can occur several times.
467Thus
468.P1
469rm *junk* *temp*
470.P2
471removes all files that contain
472.UL junk
473or
474.UL temp
475as any part of their name.
476As a special case,
477.UL *
478by itself matches every filename,
479so
480.P1
481pr *
482.P2
483prints all your files
484(alphabetical order),
485and
486.P1
487rm *
488.P2
489removes
490.ul
491all files.
492(You had better be
493.IT very
494sure that's what you wanted to say!)
495.PP
496The
497.UL *
498is not
499the only pattern-matching feature available.
500Suppose you want to print only chapters 1 through 4 and 9.
501Then you can say
502.P1
503pr chap[12349]*
504.P2
505The
506.UL [...]
507means to match any of the characters inside the brackets.
508A range of consecutive letters or digits can be abbreviated,
509so you can also do this
510with
511.P1
512pr chap[1-49]*
513.P2
514Letters can also be used within brackets:
515.UL [a\-z]
516matches any character in the range
517.UL a
518through
519.UL z .
520.PP
521The
522.UL ?
523pattern matches any single character,
524so
525.P1
526ls ?
527.P2
528lists all files which have single-character names,
529and
530.P1
531ls -l chap?.1
532.P2
533lists information about the first file of each chapter
534.UL chap1.1 \&, (
535.UL chap2.1 ,
536etc.).
537.PP
538Of these niceties,
539.UL *
540is certainly the most useful,
541and you should get used to it.
542The others are frills, but worth knowing.
543.PP
544If you should ever have to turn off the special meaning
545of
546.UL * ,
547.UL ? ,
548etc.,
549enclose the entire argument in single quotes,
550as in
551.P1
552ls \(fm?\(fm
553.P2
554We'll see some more examples of this shortly.
555.SH
556What's in a Filename, Continued
557.PP
558When you first made that file called
559.UL junk ,
560how did
561the system
562know that there wasn't another
563.UL junk
564somewhere else,
565especially since the person in the next office is also
566reading this tutorial?
567The answer is that generally each user
568has a private
569.IT directory ,
570which contains only the files that belong to him.
571When you log in, you are ``in'' your directory.
572Unless you take special action,
573when you create a new file,
574it is made in the directory that you are currently in;
575this is most often your own directory,
576and thus the file is unrelated to any other file of the same name
577that might exist in someone else's directory.
578.PP
579The set of all files
580is organized into a (usually big) tree,
581with your files located several branches into the tree.
582It is possible for you to ``walk'' around this tree,
583and to find any file in the system, by starting at the root
584of the tree and walking along the proper set of branches.
585Conversely, you can start where you are and walk toward the root.
586.PP
587Let's try the latter first.
588The basic tools is the command
589.UL pwd
590(``print working directory''),
591which prints the name of the directory you are currently in.
592.PP
593Although the details will vary according to the system you are on,
594if you give the
595command
596.UL pwd ,
597it will print something like
598.P1
599/usr/your\(hyname
600.P2
601This says that you are currently in the directory
602.UL your-name ,
603which is in turn in the directory
604.UL /usr ,
605which is in turn in the root directory
606called by convention just
607.UL / .
608(Even if it's not called
609.UL /usr
610on your system,
611you will get something analogous.
612Make the corresponding changes and read on.)
613.PP
614If you now type
615.P1
616ls /usr/your\(hyname
617.P2
618you should get exactly the same list of file names
619as you get from a plain
620.UL ls :
621with no arguments,
622.UL ls
623lists the contents of the current directory;
624given the name of a directory,
625it lists the contents of that directory.
626.PP
627Next, try
628.P1
629ls /usr
630.P2
631This should print a long series of names,
632among which is your own login name
633.UL your-name .
634On many systems,
635.UL usr
636is a directory that contains the directories
637of all the normal users of the system,
638like you.
639.PP
640The next step is to try
641.P1
642ls /
643.P2
644You should get a response something like this
645(although again the details may be different):
646.P1
647bin
648dev
649etc
650lib
651tmp
652usr
653.P2
654This is a collection of the basic directories of files
655that
656the system
657knows about;
658we are at the root of the tree.
659.PP
660Now try
661.P1
662cat /usr/your\(hyname/junk
663.P2
664(if
665.UL junk
666is still around in your directory).
667The name
668.P1
669/usr/your\(hyname/junk
670.P2
671is called the
672.UL pathname
673of the file that
674you normally think of as ``junk''.
675``Pathname'' has an obvious meaning:
676it represents the full name of the path you have to follow from the root
677through the tree of directories to get to a particular file.
678It is a universal rule in
679the
680.UC UNIX
681system
682that anywhere you can use an ordinary filename,
683you can use a pathname.
684.PP
685Here is a picture which may make this clearer:
686.P1 1
687.ft R
688.if t .vs 9p
689.if t .tr /\(sl
690.if t .tr ||
691.ce 100
692(root)
693/ | \e
694/ | \e
695/ | \e
696 bin etc usr dev tmp
697/ | \e / | \e / | \e / | \e / | \e
698/ | \e
699/ | \e
700adam eve mary
701/ / \e \e
702 / \e junk
703junk temp
704.ce 0
705.br
706.tr //
707.P2
708.LP
709Notice that Mary's
710.UL junk
711is unrelated to Eve's.
712.PP
713This isn't too exciting if all the files of interest are in your own
714directory, but if you work with someone else
715or on several projects concurrently,
716it becomes handy indeed.
717For example, your friends can print your book by saying
718.P1
719pr /usr/your\(hyname/chap*
720.P2
721Similarly, you can find out what files your neighbor has
722by saying
723.P1
724ls /usr/neighbor\(hyname
725.P2
726or make your own copy of one of his files by
727.P1
728cp /usr/your\(hyneighbor/his\(hyfile yourfile
729.P2
730.PP
731If your neighbor doesn't want you poking around in his files,
732or vice versa,
733privacy can be arranged.
734Each file and directory has read-write-execute permissions for the owner,
735a group, and everyone else,
736which can be set
737to control access.
738See
739.UL ls (1)
740and
741.UL chmod (1)
742for details.
743As a matter of observed fact,
744most users most of the time find openness of more
745benefit than privacy.
746.PP
747As a final experiment with pathnames, try
748.P1
749ls /bin /usr/bin
750.P2
751Do some of the names look familiar?
752When you run a program, by typing its name after the prompt character,
753the system simply looks for a file of that name.
754It normally looks first in your directory
755(where it typically doesn't find it),
756then in
757.UL /bin
758and finally in
759.UL /usr/bin .
760There is nothing magic about commands like
761.UL cat
762or
763.UL ls ,
764except that they have been collected into a couple of places to be easy to find and administer.
765.PP
766What if you work regularly with someone else on common information
767in his directory?
768You could just log in as your friend each time you want to,
769but you can also say
770``I want to work on his files instead of my own''.
771This is done by changing the directory that you are
772currently in:
773.P1
774cd /usr/your\(hyfriend
775.P2
776(On some systems,
777.UL cd
778is spelled
779.UL chdir .)
780Now when you use a filename in something like
781.UL cat
782or
783.UL pr ,
784it refers to the file in your friend's directory.
785Changing directories doesn't affect any permissions associated
786with a file \(em
787if you couldn't access a file from your own directory,
788changing to another directory won't alter that fact.
789Of course,
790if you forget what directory you're in, type
791.P1
792pwd
793.P2
794to find out.
795.PP
796It is usually convenient to arrange your own files
797so that all the files related to one thing are in a directory separate
798from other projects.
799For example, when you write your book, you might want to keep all the text
800in a directory called
801.UL book .
802So make one with
803.P1
804mkdir book
805.P2
806then go to it with
807.P1
808cd book
809.P2
810then start typing chapters.
811The book is now found in (presumably)
812.P1
813/usr/your\(hyname/book
814.P2
815To remove the directory
816.UL book ,
817type
818.P1
819rm book/*
820rmdir book
821.P2
822The first command removes all files from the directory;
823the second
824removes the empty directory.
825.PP
826You can go up one level in the tree of files
827by saying
828.P1
829cd ..
830.P2
831.UL .. '' ``
832is the name of the parent of whatever directory you are currently in.
833For completeness,
834.UL . '' ``
835is an alternate name
836for the directory you are in.
837.SH
838Using Files instead of the Terminal
839.PP
840Most of the commands we have seen so far produce output
841on the terminal;
842some, like the editor, also take their input from the terminal.
843It is universal in
844.UC UNIX
845systems
846that the terminal can be replaced by a file
847for either or both of input and output.
848As one example,
849.P1
850ls
851.P2
852makes a list of files on your terminal.
853But if you say
854.P1
855ls >filelist
856.P2
857a list of your files will be placed in the file
858.UL filelist
859(which
860will be created if it doesn't already exist,
861or overwritten if it does).
862The symbol
863.UL >
864means ``put the output on the following file,
865rather than on the terminal.''
866Nothing is produced on the terminal.
867As another example, you could combine
868several files into one by capturing the output of
869.UL cat
870in a file:
871.P1
872cat f1 f2 f3 >temp
873.P2
874.PP
875The symbol
876.UL >>
877operates very much like
878.UL >
879does,
880except that it means
881``add to the end of.''
882That is,
883.P1
884cat f1 f2 f3 >>temp
885.P2
886means to concatenate
887.UL f1 ,
888.UL f2
889and
890.UL f3
891to the end of whatever is already in
892.UL temp ,
893instead of overwriting the existing contents.
894As with
895.UL > ,
896if
897.UL temp
898doesn't exist, it will be created for you.
899.PP
900In a similar way, the symbol
901.UL <
902means to take the input
903for a program from the following file,
904instead of from the terminal.
905Thus, you could make up a script of commonly used editing commands
906and put them into a file called
907.UL script .
908Then you can run the script on a file by saying
909.P1
910ed file <script
911.P2
912As another example, you can use
913.UL ed
914to prepare a letter in file
915.UL let ,
916then send it to several people with
917.P1
918mail adam eve mary joe <let
919.P2
920.SH
921Pipes
922.PP
923One of the novel contributions of
924the
925.UC UNIX
926system
927is the idea of a
928.ul
929pipe.
930A pipe is simply a way to connect the output of one program
931to the input of another program,
932so the two run as a sequence of processes \(em
933a pipeline.
934.PP
935For example,
936.P1
937pr f g h
938.P2
939will print the files
940.UL f ,
941.UL g ,
942and
943.UL h ,
944beginning each on a new page.
945Suppose you want
946them run together instead.
947You could say
948.P1
949cat f g h >temp
950pr <temp
951rm temp
952.P2
953but this is more work than necessary.
954Clearly what we want is to take the output of
955.UL cat
956and
957connect it to the input of
958.UL pr .
959So let us use a pipe:
960.P1
961cat f g h | pr
962.P2
963The vertical bar
964.UL |
965means to
966take the output from
967.UL cat ,
968which would normally have gone to the terminal,
969and put it into
970.UL pr
971to be neatly formatted.
972.PP
973There are many other examples of pipes.
974For example,
975.P1
976ls | pr -3
977.P2
978prints a list of your files in three columns.
979The program
980.UL wc
981counts the number of lines, words and characters in
982its input, and as we saw earlier,
983.UL who
984prints a list of currently-logged on people,
985one per line.
986Thus
987.P1
988who | wc
989.P2
990tells how many people are logged on.
991And of course
992.P1
993ls | wc
994.P2
995counts your files.
996.PP
997Any program
998that reads from the terminal
999can read from a pipe instead;
1000any program that writes on the terminal can drive
1001a pipe.
1002You can have as many elements in a pipeline as you wish.
1003.PP
1004Many
1005.UC UNIX
1006programs are written so that they will take their input from one or more files
1007if file arguments are given;
1008if no arguments are given they will read from the terminal,
1009and thus can be used in pipelines.
1010.UL pr
1011is one example:
1012.P1
1013pr -3 a b c
1014.P2
1015prints files
1016.UL a ,
1017.UL b
1018and
1019.UL c
1020in order in three columns.
1021But in
1022.P1
1023cat a b c | pr -3
1024.P2
1025.UL pr
1026prints the information coming down the pipeline,
1027still in
1028three columns.
1029.SH
1030The Shell
1031.PP
1032We have already mentioned once or twice the mysterious
1033``shell,''
1034which is in fact
1035.UL sh (1).
1036The shell is the program that interprets what you type as
1037commands and arguments.
1038It also looks after translating
1039.UL * ,
1040etc.,
1041into lists of filenames,
1042and
1043.UL < ,
1044.UL > ,
1045and
1046.UL |
1047into changes of input and output streams.
1048.PP
1049The shell has other capabilities too.
1050For example, you can run two programs with one command line
1051by separating the commands with a semicolon;
1052the shell recognizes the semicolon and
1053breaks the line into two commands.
1054Thus
1055.P1
1056date; who
1057.P2
1058does both commands before returning with a prompt character.
1059.PP
1060You can also have more than one program running
1061.ul
1062simultaneously
1063if you wish.
1064For example, if you are doing something time-consuming,
1065like the editor script
1066of an earlier section,
1067and you don't want to wait around for the results before starting something else,
1068you can say
1069.P1
1070ed file <script &
1071.P2
1072The ampersand at the end of a command line
1073says ``start this command running,
1074then take further commands from the terminal immediately,''
1075that is,
1076don't wait for it to complete.
1077Thus the script will begin,
1078but you can do something else at the same time.
1079Of course, to keep the output from interfering
1080with what you're doing on the terminal,
1081it would be better to say
1082.P1
1083ed file <script >script.out &
1084.P2
1085which saves the output lines in a file
1086called
1087.UL script.out .
1088.PP
1089When you initiate a command with
1090.UL & ,
1091the system
1092replies with a number
1093called the process number,
1094which identifies the command in case you later want
1095to stop it.
1096If you do, you can say
1097.P1
1098kill process\(hynumber
1099.P2
1100If you forget the process number,
1101the command
1102.UL ps
1103will tell you about everything you have running.
1104(If you are desperate,
1105.UL kill\ 0
1106will kill all your processes.)
1107And if you're curious about other people,
1108.UL ps\ a
1109will tell you about
1110.ul
1111all
1112programs that are currently running.
1113.PP
1114You can say
1115.P1 1
1116(command\(hy1; command\(hy2; command\(hy3) &
1117.P2
1118to start three commands in the background,
1119or you can start a background pipeline with
1120.P1
1121command\(hy1 | command\(hy2 &
1122.P2
1123.PP
1124Just as you can tell the editor
1125or some similar program to take its input
1126from a file instead of from the terminal,
1127you can tell the shell to read a file
1128to get commands.
1129(Why not? The shell, after all, is just a program,
1130albeit a clever one.)
1131For instance, suppose you want to set tabs on
1132your terminal, and find out the date
1133and who's on the system every time you log in.
1134Then you can put the three necessary commands
1135.UL tabs , (
1136.UL date ,
1137.UL who )
1138into a file, let's call it
1139.UL startup ,
1140and then run it with
1141.P1
1142sh startup
1143.P2
1144This says to run the shell with the file
1145.UL startup
1146as input.
1147The effect is as if you had typed
1148the contents of
1149.UL startup
1150on the terminal.
1151.PP
1152If this is to be a regular thing,
1153you can eliminate the
1154need to type
1155.UL sh :
1156simply type, once only, the command
1157.P1
1158chmod +x startup
1159.P2
1160and thereafter you need only say
1161.P1
1162startup
1163.P2
1164to run the sequence of commands.
1165The
1166.UL chmod (1)
1167command marks the file executable;
1168the shell recognizes this and runs it as a sequence of commands.
1169.PP
1170If you want
1171.UL startup
1172to run automatically every time you log in,
1173create a file in your login directory called
1174.UL .profile ,
1175and place in it the line
1176.UL startup .
1177When the shell first gains control when you log in,
1178it looks for the
1179.UL .profile
1180file and does whatever commands it finds in it.
1181We'll get back to the shell in the section
1182on programming.