User Tools

Site Tools


unix_survival

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revision Both sides next revision
unix_survival [2020/03/11 17:33]
smj created
unix_survival [2020/04/08 21:25]
joshd
Line 1: Line 1:
 **UNIX Command Reference** **UNIX Command Reference**
  
-The command prompt in UNIX is called the //shell// Here is a list of common UNIX commands which will work across many different versions of UNIX with discrepancies in Example/Notes.+The command prompt in UNIX is called the //shell//, which typically uses a dollar sign ($) as its prompt.  Here is a list of common UNIX commands which will work across many different versions of UNIX with discrepancies in Example/Notes.
  
 ||Command||Description||Examples||Notes|| ||Command||Description||Examples||Notes||
 ||as||ASsembler||//as input.s//|||| ||as||ASsembler||//as input.s//||||
-||cc||C Compiler||//cc input.c//|||| +||cc||C Compiler||//cc input.c//||Creates an executable named //a.out// by default|| 
-||cd||Change working Directory||//cd tmp//||on Version 6 this command is //chdir//|| +||cd||Change working Directory||//cd /usr/local/games//||on Version 6 this command is //chdir//|| 
-||df||Disk Free||//df//||May take time to complete on some systems||+||df||Disk Free||//df//||Displays summary of free disk space. May take time to complete on some systems||
 ||ed||EDitor||//ed filename//||[[ED Survival|ED is the standard (line) text editor]]|| ||ed||EDitor||//ed filename//||[[ED Survival|ED is the standard (line) text editor]]||
 ||echo||Echo||//echo ${HOME}//||Prints the value assigned to the variable HOME|| ||echo||Echo||//echo ${HOME}//||Prints the value assigned to the variable HOME||
Line 13: Line 13:
 ||ld||Link Loader||//ld inputfile//|||| ||ld||Link Loader||//ld inputfile//||||
 ||ls||LiSt directory||//ls -l//||provides a long LiSting|| ||ls||LiSt directory||//ls -l//||provides a long LiSting||
-||man||MANual||//man man//||On some systems, displays online manual pages||+||man||MANual||//man ls//||On some systems, displays online manual pages.  Try "man man" to learn more about "man."||
 ||ps||Process Status||//ps -a// or //ps -l//||prints All or Long Process Status|| ||ps||Process Status||//ps -a// or //ps -l//||prints All or Long Process Status||
 ||pwd||Present Working Directory||//pwd//||Prints the working directory|| ||pwd||Present Working Directory||//pwd//||Prints the working directory||
-||set||SETting||//set//||Displays the shell environment settings (see //env//)||+||set||SET or display shell parameters||//set//||Sets or displays the shell environment settings (see //env//)||
 ||vi||VIsual editor||//vi filename//||[[VI Survival|vi is a screen editor]]|| ||vi||VIsual editor||//vi filename//||[[VI Survival|vi is a screen editor]]||
  
-On some systems typing //games// will print a list of games.+On some systems typing //games// will print a list of games.  
  
 ||directory||description|| ||directory||description||
Line 26: Line 26:
 ||/etc||This is the system directory|| ||/etc||This is the system directory||
 ||/lib||System library files|| ||/lib||System library files||
-||/usr||USeR directory - contains additional binaries, libraries, manpages||+||/usr||"Unix System Resources" or "USeRdirectory, depending on who you ask - contains additional binaries, libraries, manpages|| 
 +||/usr/games or /usr/local/games||Usually contains the standard UNIX games|| 
 + 
 +** Useful UNIX References ** 
 + 
 +[[http://www.bitsavers.org/pdf/stanford/stanford_4.2_BSD_manual/4.2_BSD_Vol_2C.pdf|The 4.2BSD Manual]] is a good guide to BSD systems (generally applicable to 4.3, 2.11 and V8 Research UNIX). 
 + 
 +[[https://www.livingcomputers.org/UI/UserDocs/UNIX-SVR3-(WE-3B2)/UNIX_System_V_Users_Guide_Second_Edition_1987.pdf|UNIX System V User's Guide (Second Edition)]] and [[https://livingcomputers.org/UI/UserDocs/UNIX-SVR3-(WE-3B2)/UNIX_System_V_Users_Reference_Manual_1987.pdf|UNIX System V User's Reference]] are a useful references for System V-based systems (or close relatives). 
 + 
 +[[https://www.livingcomputers.org/UI/UserDocs/Unix-v7-1/UNIX_Programmers_Manual_Seventh_Edition_Vol_2_1983.pdf|The UNIX Programmer's Manual (7th Edition)]] is an excellent overview for using UNIX for software development. 
 + 
 +[[http://man.cat-v.org/|man.cat-v.org]] provides HTML-ized versions of //man// pages for many historical UNIX systems. 
 + 
 +[[https://wfjm.github.io/home/ouxr/|Old Unix XRef]] gives a very nice cross-indexed look at the 2.11BSD UNIX source code, if you're interested in seeing how the system is constructed from the kernel on up, or if you're interested in hacking the kernel source yourself. 
 + 
 +** Using the C Compiler ** 
 + 
 +This wiki cannot provide an extensive tutorial for the C language, but we'll provide an example or two to get you started.  [[https://archive.org/details/TheCProgrammingLanguageFirstEdition/page/n13/mode/2up|The C Programming Language]] is the classic reference for this (and belongs on every UNIX hacker's bookshelf) and should apply to all of the UNIX systems we have online (although some may also support the later ANSI C specification(s) as well. 
 + 
 +Use the editor of your choice to create the source file.  We'll use //ed// here, as it's common to all UNIX systems, but //vi// may be a more friendly choice.  This program is a version of your average "Hello, world!" program.  It uses //printf// to output the //string// "Hello, world! to //stdout// and then exits.  This example uses [[https://en.wikipedia.org/wiki/C_(programming_language)#K&R_C|K&R]] syntax: 
 + 
 +<code> 
 +$ ed hello.c 
 +?hello.c 
 +
 +int main(argc, argv) 
 +   int argc; 
 +   char** argv; 
 +
 +   printf("Hello, world!\n"); 
 +   return 0; 
 +
 +
 +
 +98 
 +
 +
 +</code> 
 + 
 +You should now have a file on disk named "hello.c": 
 + 
 +<code> 
 +$ ls -l hello.c 
 +-rw-rw-rw-   1 user       user             98 Apr  9 02:36 hello.c 
 +
 +</code> 
 + 
 +This new C source file can be //compiled// into an executable using //cc// The simple syntax for this is: 
 + 
 +<code> 
 +$ cc hello.c 
 +
 +</code> 
 + 
 +This produces an output file named //a.out// You can run this directly: 
 + 
 +<code> 
 +$ ./a.out 
 +Hello, world! 
 +
 +</code> 
 + 
 +Optionally, you can use the "-o" compiler flag to specify the output filename: 
 + 
 +<code> 
 +$ cc -o hello hello.c 
 +
 +</code> 
 + 
 +Which will produce an output file named //hello//
 + 
 +<code> 
 +$ ./hello 
 +Hello, world! 
 +</code> 
 + 
 +Here's a more complex program.  It makes use of //for// loops to print a small multiplication table. 
 + 
 +<code> 
 +$ ed table.c 
 +?table.c 
 +
 +int main(argc, argv) 
 +    int argc; 
 +    char** argv; 
 +
 +    int i,j; 
 +     
 +    /* Use nested 'for' loops to print a 4x4 multiplication table. */ 
 +    for(i=1;i<5;i++) 
 +    { 
 +        for(j=1;j<5;j++) 
 +        { 
 +            /* '%d' means 'Substitute a numerical value here' */ 
 +            printf("%d x %d = %d\t", i, j, i * j); 
 +        } 
 +         
 +        /* '\n' is the "newline" character -- this moves the cursor to the next line 
 +           for the next row of the table */ 
 +        printf("\n"); 
 +    } 
 + 
 +    return 0;    
 +
 +
 +
 +516 
 +
 +
 +</code> 
 + 
 +Compiling this as in the above example and running it yields: 
 + 
 + 
 +<code> 
 +$ cc table.c 
 +$ ./a.out 
 +1 x 1 = 1       1 x 2 = 2       1 x 3 = 3       1 x 4 = 4 
 +2 x 1 = 2       2 x 2 = 4       2 x 3 = 6       2 x 4 = 8 
 +3 x 1 = 3       3 x 2 = 6       3 x 3 = 9       3 x 4 = 12 
 +4 x 1 = 4       4 x 2 = 8       4 x 3 = 12      4 x 4 = 16 
 +
 +</code> 
  
unix_survival.txt · Last modified: 2020/04/08 23:16 by joshd