UNIX is a flexible, multi-user, general purpose computer operating system. Created by computer using professionals, for speed and efficiency, UNIX commands typically involve very few keystrokes. The terse commands frequently appear to be cryptic and non-intuitive. However once you begin to use UNIX more frequently you will begin to notice an underlying logic to the system. Below is a list of some of the most frequently used UNIX operating system commands. If you are interested in using UNIX for running basic software packages (e.g., SPSS, SAS, LIMDEP) you will probably find these commands sufficient for most of your needs. Keep in mind that UNIX is a case sensitive operating system. This means it matters whether you type in upper or lower case. Keeping with the tradition of few keystrokes most of the commands you will encounter in UNIX are lower case. If you are uncertain which case to use in a particular situation you should consider lower case the default. Also, UNIX commands typically take the form of a command that may be followed by options. Option specifications are preceded by a switch character, the hyphen (-), and provide more information about how you wish the command to be executed. In this handout, options will be displayed inside [square brackets] to indicate the fact that their presence is optional. However, in typing the actual command, the brackets should be omitted. Usually multiple options may be included after a command using only one hyphen (i.e., you would use -ltas rather than -l -t -a –s, although the latter would also work). For Files: File commands are used to create, access, and change attributes of files. The general format of a file command is: command [-options] filename where filename is the file to be processed and options describe the specific nature of the processing. Some commands have slightly different formats, requiring, for example, two file names following the command, or no file name, or no options. NOTE: in the examples you will frequently see a % sign.
This is the most frequently encountered UNIX prompt character.
List files and directories: ls [-ltas] This command will display a listing of your files and directories. By using wildcards (discussed later) you may also display a subset file listing. The option -l (long) will provide you with extra information
about your files and directories. -l is perhaps most useful for reading
about file permissions.
-a lists all the entries. Typically UNIX hides special files beginning with a period, however this option causes these files to be included in the directory listing. -s will tell you the size of the files in kilobytes. For more information about the various switches available use the on-line help feature (described later). % ls -a first.sps .signature first.lis /home /mail data.sys
Creating or Editing a file: pico filename In order to create a new file or edit an existing file we recommend that you use the pico (PIne COmposer) editor. The editor has a list of the most frequently used commands displayed at the bottom of the screen, and there is a help feature available inside the editor. Simply type the word pico followed by the name of the file you would like to create or edit. When you are done editing type CTRL-x to exit. You will be asked if you would like to save your changes. If you type y you will be asked for a filename. Remember, if you use a name of an already existing file, that file will be overwritten (deleted). Copy files: cp filename filename2 If you would like to make a copy of an existing file to another name, cp is the command to use. You will not receive a confirmation if the command is executed successfully, however you will receive an error if you have done something wrong. You may confirm that the file was copied successfully by pulling up a file list. List the file you wish to copy first in the command line. % cp first.sps second.sps
Rename files: mv filename filename2 To give an existing file a new name you would use the mv command. List the file you wish to rename first in the command line and the new name second. This command is also useful for transferring a file to a new directory. As with the cp command you will receive no confirmation if the command has been executed successfully. % mv gss91.sys gss91big.sys
Delete files: rm filename This command will remove a file stored in your account that you no longer wish to keep. After typing the command line and hitting return, you will be given one last opportunity to change your mind. You will see a prompt that includes the filename and ends with a question mark. If you type the letter y at this prompt the file will be deleted, but if you press any other key on the keyboard the file will not be destroyed. Again, you will not receive any confirmation if the file has indeed been deleted and would need to use the ls command to be certain. % rm first.sps first.sps ? y
Display a file: cat filename This command will type out the contents of a file for you to view. Follow the command with the name of the file or files that you wish to examine. (The command name is an abbreviation of the word concatenate.) % cat first.sps get file=‘gss91big.sys’. frequencies age sex race. finish.
Page through a text file: more [-d] filename This command is similar to cat, however was designed to accommodate larger files that would normally scroll off the screen. By using more rather than cat the file can be viewed page by page. In the bottom left corner of each page will be the word -more- . Press the space bar to continue paging through the text, or the letter q to quit. Follow the command with the name of the file you wish to view. The d switch changes the message in the bottom left of the screen from -more- to press space to continue or ‘q’ to quit. % more -d first.lis << page of text here >> press space to continue or ‘q’ to quit <space>
more Unix Questions
Unix Forum - Do you have a UNIX Question? Unix Books :-
Return to : - Unix System Administration Hints and Tips (c) www.gotothings.com All material on this site is Copyright.
|