Vous êtes sur la page 1sur 10

Basic Commands and Tips for the Future UNIX Professional

Dr. Adrian Nunez and Preetham Lakshmikanthan, E-Mail : {anunezal@syr.edu and plakshmi@syr.edu}, VSDCAD Laboratory, 0-213 Center for Science and Technology, Syracuse University, Syracuse, New York - 13244. September 7, 2004
Abstract This document is a simple guide to get new users of UNIX familiar with the Solaris Operating System (OS). No prior knowledge of the UNIX OS is necessary and by stepping through this tutorial, the user gets a feel for what UNIX is. Working with the commands listed in this document will get you through most of the basic navigation steps required in UNIX. The authors do not claim to be experts in UNIX and this document was written to facilitate students who are novices in UNIX. Also, it is assumed that all students have already registered with CIT and have a valid ECS account and password.

Logging onto an ECS Solaris Machine


1. Directly on a Solaris Machine : Individual ECS Solaris Machines are located in the Stars Cluster (CST 1-211) and the Foundry lab (CST 3-118). These are machines that should be labeled with the Sun Microsystems logo. 2. From a Windows Machine : It is possible to log into a UNIX server (apollo.ecs.syr.edu, enyo.ecs.syr.edu) using a PC. However, for this you will require to have an X-Windows emulator (X-Win or Exceed) running on the PC to able to connect to the UNIX server. Were not sure if the X-Win software is installed on all the PCs and dont give any guarantees about that.

There are two ways you can log into Solaris machines :

It is advisable directly logging onto a Solaris machine and this tutorial is written from that point of view. > You will get to a login screen which asks you for your user-name. Type in your user-name at this prompt. Please note that UNIX is Case Sensitive and so if you type in USernaMe instead of username, UNIX will not be able to recognize your login info and will give you an error saying re-enter login or password. > Now the login screen asks you for your password. Type in your password at this prompt. If you make a mistake, you will be asked to re-enter your login and password information. > Once you nish up with the login screen, a form comes up asking you to choose your desktop style. Say you choose the Common Desktop Environment (CDE). This will get you to a screen with a workspace toolbar at the lower end. Once you are at this point, you have successfully logged into your ECS account. 1

Opening out X-Terminals

X-Terminals or X-Terms are nothing but shells that you work in. This is equivalent to the prompt in DOS or Windows. You can get X-Terms in two ways 1. Clicking the Rightmost Solaris Mouse button to get to a Workspace Menu : At this menu, click > Hosts > This host 2. From the Workspace Toolbar at the lower end of your screen : Three boxes to the right of the EXIT button is the Performance Meter. On top of this is a small triangle symbol (). When you place the mouse over this, it says Hosts. Click > to bring up the Hosts pop-up. Click > This Host. This is your UNIX shell or X-Term. Each shell is a white rectangular box which you can re-size. Commands can be typed in inside these shells at the command prompt. A typical command prompt inside your shell looks like the following [machinename] [number]: Example apollo 51: In the above example, apollo is the name of the machine you have logged into and the number 51 represents the number of commands you have typed in at the prompt till now.

UNIX Commands from your X-Term

The following are the most common commands used to navigate UNIX. Please note that the commands need to be executed by pressing the return key after typing the command in your shell. 1. clear This command is the equivalent of cls (clear screen) in DOS and is used to clear an X-Term. 2. ls This command is used to list les and directories. If you are logging into your system for the rst time, you may not see anything listed. Example apollo 52: ls <return> analog_design_course/ cse664classlist.xls layout-xl.method prog/ senna.jpg unix_tutorial/ cadence.tar.gz iasted04/ layout_tutorials/ public_html/ spice/ user_guide_2/ calendar latex_samples/ miscellaenous/ scratch@ summer2004/ vlsi05/

Names ending with a / sign are directories. Names ending with @ are links. Later in the document, we will explain what these are.

3. ls -al This is an extension of the list command shown above, but, with the switch -al. Please note that there is a space between ls and the -al. The a option lists all les including hidden dot . les. The l option gives a long listing of the le - information like the user-name, size of le, date created are all displayed. Example apollo 53: ls -al <return> total 88 drwxr-xr-x drwxr-xr-x -rw-r--r--rwx------rw-r--r--rw-r--r--rw-r--r--rw------4. mkdir This command is used to make a directory. Example apollo 54: mkdir zzz dir <return> Now to see if the directory is created, you would use the ls command. apollo 55: ls <return> analog_design_course/ cse664classlist.xls layout-xl.method prog/ senna.jpg unix_tutorial/ zzz_dir/ cadence.tar.gz iasted04/ layout_tutorials/ public_html/ spice/ user_guide_2/ calendar latex_samples/ miscellaenous/ scratch@ summer2004/ vlsi05/

2 36 1 1 1 1 1 1

plakshmi plakshmi plakshmi plakshmi plakshmi plakshmi plakshmi plakshmi

students students students students students students students students

105 4096 3 245 374 9292 5190 8375

Sep Sep Sep Sep Sep Sep Sep Sep

3 3 3 3 3 3 3 3

13:37 13:32 13:44 10:19 13:33 13:33 13:33 13:37

./ ../ .somefile Makefile* user_guide.aux user_guide.dvi user_guide.log user_guide.tex

We see that the directory zzz dir/ is added to the previous list (compared to what we saw in 2). 5. pwd This command prints the present working directory. This is the path upto where you are right now. Example apollo 56: pwd <return>

/home/hd02/p/plakshmi The above shows that Im in my home directory at present. 6. cd This command is used to change to a particular directory. Example 1 apollo 57: cd zzz dir <return> Now to see where you are, you would use the pwd command. apollo 58: pwd <return> /home/hd02/p/plakshmi/zzz dir We see that because we changed directory, we are currently in zzz dir/ (compared to what we saw in 5). Example 2 apollo 59: cd /usr/ecs/ncsu cdk-1.3/local/bin <return> apollo 60: pwd <return> /usr/ecs/ncsu cdk-1.3/local/bin Example 3 - Go up 2 directories apollo 61: cd ../../ <return> apollo 62: pwd <return> /usr/ecs/ncsu cdk-1.3 We see that weve gone up 2 directory hierarchies, i.e, above bin/ and above local/. Example 4 apollo 63: cd <return> apollo 64: pwd <return> /home/hd02/p/plakshmi The use of just the cd command from any point always takes you to your home directory.

7. rm This command is used to delete les. Use it extremely carefully. Windows gives you a trash-can from which you can undelete les. On the other hand, les once deleted in Unix are gone. There is no way you can recover them unless the UNIX system administrator recovers it from the backup data (if your data has been backed up). Normally, the rm command is aliased to an interactive mode in which UNIX asks you for a conrmation (yes/no) to delete a le before actually doing so. Example apollo 65: rm .somele <return> rm: remove .somele (yes/no)? yes Type yes and it removes .somele Now to see the le long listing, you would use the ls -al command. apollo 66: ls -al <return> total 88 drwxr-xr-x drwxr-xr-x -rwx------rw-r--r--rw-r--r--rw-r--r--rw-------

2 36 1 1 1 1 1

plakshmi plakshmi plakshmi plakshmi plakshmi plakshmi plakshmi

students students students students students students students

105 4096 245 374 9292 5190 8375

Sep Sep Sep Sep Sep Sep Sep

3 3 3 3 3 3 3

13:37 13:32 10:19 13:33 13:33 13:33 13:37

./ ../ Makefile* user_guide.aux user_guide.dvi user_guide.log user_guide.tex

We see that the le .somele (compared to what we saw in 3) is gone. 8. rmdir This command is used to remove a directory. The point to be noted is that this command can be used only if the directory is empty, i.e, it has no les contained within. If you try to remove a nonempty directory, UNIX complains saying that the directory is not empty. First remove the les within that directory using the rm command seen in 7. Also, to remove a directory, you have to be at least 1 level higher in the directory structure than the directory you want to remove. Example 1 (directory not empty) apollo 67: rmdir zzz dir <return> rmdir: directory zzz dir/: Directory not empty apollo 68: cd zzz dir <return> Go into that directory apollo 69: rm [les] <return> Remove all les apollo 70: cd .. <return> Go back up 1 level higher than zzz dir Now that weve removed all the les inside the zzz dir directory, we can go ahead remove that empty directory.

Example 2 (directory empty) apollo 71: rmdir zzz dir <return> apollo 72: ls <return> analog_design_course/ cse664classlist.xls layout-xl.method prog/ senna.jpg unix_tutorial/ cadence.tar.gz iasted04/ layout_tutorials/ public_html/ spice/ user_guide_2/ calendar latex_samples/ miscellaenous/ scratch@ summer2004/ vlsi05/

We see that the directory zzz dir has been removed (compared to what we saw in 4). 9. cp This command is used to copy les. The rst parameter after cp is the source and the second parameter is the destination. Example 1 (File to File Copy in Same Directory) apollo 73: cp senna.jpg ayrton senna.jpg <return> apollo 74: ls <return> analog_design_course/ calendar latex_samples/ miscellaenous/ scratch@ summer2004/ vlsi05/ ayrton_senna.jpg cse664classlist.xls layout-xl.method prog/ senna.jpg unix_tutorial/ cadence.tar.gz iasted04/ layout_tutorials/ public_html/ spice/ user_guide_2/

We see that the le senna.jpg is copied in the same directory to a new le called ayrton senna.jpg. Example 2 (File to File Copy in Dierent Directory) apollo 75: cp senna.jpg unix tutorial/ <return> apollo 76: ls -al unix tutorial/ <return> total 88 drwxr-xr-x drwxr-xr-x -rwx------rw-------rw-r--r--rw-r--r--rw-r--r--rw-------

2 36 1 1 1 1 1 1

plakshmi plakshmi plakshmi plakshmi plakshmi plakshmi plakshmi plakshmi

students students students students students students students students

105 4096 245 104286 374 9292 5190 8375

Sep Sep Sep Sep Sep Sep Sep Sep

3 3 3 3 3 3 3 3

13:37 13:32 10:19 16:30 13:33 13:33 13:33 13:37

./ ../ Makefile* senna.jpg user_guide.aux user_guide.dvi user_guide.log user_guide.tex

We see that the le senna.jpg is copied in the unix tutorial directory with the same name. 10. mv

This command is used to rename les or move les/directories across the le system. The rst parameter after mv is the source and the second parameter is the destination. Example 1 (Renaming a le) apollo 73: mv calendar plkcal <return> apollo 74: ls <return> analog_design_course/ iasted04/ layout_tutorials/ prog/ senna.jpg unix_tutorial/ cadence.tar.gz latex_samples/ miscellaenous/ public_html/ spice/ user_guide_2/ cse664classlist.xls layout-xl.method plkcal scratch@ summer2004/ vlsi05/

We see that the le calendar no longer exists (as compared to 4) and has been renamed to plkcal. Example 2 (Moving a le to a Dierent Directory) apollo 75: mv plkcal unix tutorial/ <return> apollo 76: ls <return> analog_design_course/ iasted04/ layout_tutorials/ public_html/ spice/ user_guide_2/ cadence.tar.gz latex_samples/ miscellaenous/ scratch@ summer2004/ vlsi05/ cse664classlist.xls layout-xl.method prog/ senna.jpg unix_tutorial/

The le plkcal has been moved to the unix tutorial directory and hence is missing from here. apollo 77: ls -al unix tutorial/ <return> total 88 drwxr-xr-x drwxr-xr-x -rwx------rw-------rw-------rw-r--r--rw-r--r--rw-r--r--rw------2 36 1 1 1 1 1 1 1 plakshmi plakshmi plakshmi plakshmi plakshmi plakshmi plakshmi plakshmi plakshmi students students students students students students students students students 105 4096 245 3235 104286 374 9292 5190 8375 Sep Sep Sep Sep Sep Sep Sep Sep Sep 3 3 3 1 3 3 3 3 3 13:37 13:32 10:19 19:53 16:30 13:33 13:33 13:33 13:37 ./ ../ Makefile* plkcal senna.jpg user_guide.aux user_guide.dvi user_guide.log user_guide.tex

We see that the le plkcal is in the unix tutorial directory now. 11. man This is UNIX online help. You use man in conjunction with any other UNIX command to get help and examples. Example apollo 78: man cp <return>

------------------------------------------------------------------User Commands cp(1) NAME cp - copy files SYNOPSIS /usr/bin/cp [ -fip ] : : /usr/xpg4/bin/cp -r | -R [ -fip ] source_dir ... target

source_file

target_file

DESCRIPTION In the first synopsis form, neither source_file nor target_file are directory files, nor can they have the same name. The cp utility will copy the contents of source_file : : ------------------------------------------------------------------Use space-bar to go forward to the next page and the key q to quit man. 12. cat This command is used to display les or concatenate les. Concatenation is the process of merging/appending les to each other. Example 1 (Display) apollo 79: cat unix tutorial/Makele <return> This shows the contents of a le called Makele present in the unix tutorial directory, which is as follows : ------------------------------------------------------------------all : run_latex run_latex : latex user_guide; latex user_guide; xdvi user_guide.dvi& clean : /bin/rm -rf *.aux *.log *.dvi *.ps *.pdf *~ ------------------------------------------------------------------Example 2 (Append) apollo 80: cat unix tutorial/somele >> unix tutorial/Makele <return> The >> is the append operator. Contents of the source le (somele) are appended to the end of the destination le (Makele).

The following shows the contents of Makele after the append operation : ------------------------------------------------------------------all : run_latex run_latex : latex user_guide; latex user_guide; xdvi user_guide.dvi& clean : /bin/rm -rf *.aux *.log *.dvi *.ps *.pdf *~ pdf : dvips user_guide.dvi -o user_guide.ps; ps2pdf user_guide.ps; acroread user_guide.pdf& ------------------------------------------------------------------From the above we can conclude that somele contained the following text as this is what was appended to the original Makele. ------------------------------------------------------------------pdf : dvips user_guide.dvi -o user_guide.ps; ps2pdf user_guide.ps; acroread user_guide.pdf& ------------------------------------------------------------------13. lpr and enscript These commands are used to print les on some attached network printer. lpr is used for printing postscript and other les, while enscript is typically used for text les. The general format is [lpr (or) enscript] -P[printername] [lename] Example 1 (Printing a postscript le to the Stars Cluster Printer) apollo 81: lpr -Pstars lename.ps <return> Example 2 (Printing a text le to the Foundry lab Printer) apollo 82: enscript -Pfoundry myle.txt <return> Example 3 (Printing to the CST 2nd oor Windows Lab Printer) apollo 83: lpr -Pcst2122pcl6@phoebe.syr.edu lename.ps <return>

UNIX Editor
1. vi 2. emacs

There are various editors that can be used in Unix. Some of them are enumerated as follows :

3. pico 4. xemacs Tutorials are there online for each of these editors and learning to use them will take a while. The easiest editor for a beginner is the simple text editor given along-with the UNIX OS. - Right click on the mouse (on the Unix background and not in your shell). This brings up the Workspace Menu. - Click Applications > Text Editor. This brings up the text editor. Type in what you want. - To save the le, click on File > Save. It brings up the Text Editor - Save As gui. Enter the path and the lename to save your le. Your edited text le will now be present wherever you save it. You can view it using the cat command.

Online Links to Unix Tutorials

These are a few links (the ones after the 1st link) that popped up with a google search. There are books in the library and other resources for those interested in probing UNIX further. However, please strengthen your UNIX skills ONLY in your spare time. That said, here are some useful links : - http://bear.ces.cwru.edu/eecs_cad/tut_unix.txt (Unix Cookbook link from Dr. Nunezs CSE 664 webpage)

- http://www.unixtools.com/tutorials.html

- http://www.ee.surrey.ac.uk/Teaching/Unix/

- http://www.isu.edu/departments/comcom/unix/workshop/unixindex.html

- http://www.cs.wright.edu/~pmateti/Courses/333/Notes/

- http://heather.cs.ucdavis.edu/~matloff/unix.html

- http://www2.ocean.washington.edu/unix.tutorial.html

- http://instaar.colorado.edu/~peckhams/tutors.html

- http://www.raycosoft.com/rayco/support/resources.html

- http://www.geocities.com/r_palwai/unix_vi.htm

- http://www.unix-manuals.com/

10

Vous aimerez peut-être aussi