|
Unix Tutorial 1.2: Command Summary II: More Basic Commands |
| Print |
|
|
Printing files
% lpr -P printer_name filename(s)
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 newdirectory |
copy the files to a different directory with same filenames |
Renaming a file
| % mv oldname newname |
give the file a new name |
| % mv ofile1 ofile2 ... ofilen newdirectory |
put the files into 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
| % 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.
Abbreviations: u=user, o=others, g-group, a=all, r=read, w=write,
x=execute, + adds permission, - removes it. |
Compiling a C program
| % cc progname.c |
- a.out [ executable file ] Source must end in .c |
| % cc -o exfilename progname |
- exfilename [ executable file ] |
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
| % mail |
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). |
|