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