Printing files
% lp filename
Creating a short file very quickly
% cat > filename type text CTRL-D - everything typed until CTRL-D is stored in filename
Seeing contents of a file on the screen
% cat filename | entire file |
% more filename | entire file by pages; RETURN to see one more line, spacebar for a whole page |
% less filename | entire file by pages; you can move either direction |
% head filename | first 10 lines of the file |
% tail filename | last 10 lines of the file |
% tail -50 filename | both head and tail can take a number of lines |
Copying a file
% cp oldfile dir/newfile | filenames may contain directories also |
% cp ofile1 ofile2 ... ofilen subdir | copy the files with same filenames to a different directory |
Renaming a file
% mv oldname newname | give the file a new name |
% mv ofile1 ofile2 ... ofilen subdir | move the files to a different directory |
Giving more than one name to the same file
% ln fname name | if name is a directory, the link is made so an entry of name occurs in the directory name/fname. A link gives another name to the SAME file. Both names will work to get the file; removing one name does not remove the actual file. The file itself will need link (only be removed when all links are deleted). |
Changing file protection
Abbreviations:
% chmod o-w, u+r fname | set fname to be unreadable by others, readable by owner |
% chmod a+x | allow everyone to execute the file; if a directory, this permits searching. |
Compiling a C program
% cc progname.c | creates executable file a.out. Source file name must end in .c |
% cc -o larry progname.c | creates executable file larry |
Input/Output Redirection
Redirection works for compiled programs and Unix commands.
% command < inputfile | Take input from file instead of keyboard. |
% a.out > outputfile | Write output to file instead of screen. |
% a.out < inputfile > outputfile | Read from a file and write to a file. |
Communicating with others in the Unix Operating System
Read and reply to messages. | |
% mail user1 | Send message to user1. A list of users may be given. |
% mail user1 < fname | Send the file fname to the user(s) listed. |
% write otheruser | Sends message to someone currently logged on. Type the message, ending with CTRL-d. |
% talk otheruser | Split-screen messages to and from someone currently logged on. |
% mail laurel:csc123456789 | Send mail to someone at their Unix account. |
Piping the output of one command as the input to another command
% command1 | command2 | command3
Control Characters
CTRL-C | Terminates a process. |
CTRL-D | End-of-text character; logout; end a process. |
CTRL-Z | Suspends a process (can be restarted). |