Your SlideShare is downloading. ×
0
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Unix Basics 04sp
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Unix Basics 04sp

879

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
879
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
48
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Transcript

    • 1. What is Unix? <ul><li>A multi-user networked operating system </li></ul><ul><ul><li>“Operating System” </li></ul></ul><ul><ul><ul><li>Handles files, running other programs, input/output </li></ul></ul></ul><ul><ul><ul><li>Just like DOS or Windows </li></ul></ul></ul><ul><ul><li>“Networked” </li></ul></ul><ul><ul><ul><li>Designed for server use </li></ul></ul></ul><ul><ul><ul><li>Networking is an intrinsic part of the system </li></ul></ul></ul><ul><ul><li>“Multi-user” </li></ul></ul><ul><ul><ul><li>Every user has different settings and permissions </li></ul></ul></ul><ul><ul><ul><li>Multiple users can be logged in simultaneously </li></ul></ul></ul><ul><li>Tons of fun!!!  </li></ul>This tutorial provided by UW ACM http://www.cs.washington.edu/orgs/acm/ Questions to ethel@cs, awong@cs
    • 2. IWS (Instructional Work Servers) <ul><li>There are 4 instructional Unix servers: </li></ul><ul><ul><li>attu1, attu2, attu3 and attu4. </li></ul></ul><ul><ul><li>They can be accessed through attu.cs </li></ul></ul><ul><li>Accessing the servers: </li></ul><ul><ul><li>Terminal Programs: </li></ul></ul><ul><ul><ul><li>telnet (insecure; cannot be used) </li></ul></ul></ul><ul><ul><ul><li>ssh (via the TeraTerm, Putty, or official SSH programs) </li></ul></ul></ul><ul><ul><ul><ul><li>Start -&gt; Program Files -&gt; Unix Connectivity -&gt; Ssh -&gt; SSH-x attu </li></ul></ul></ul></ul><ul><ul><li>File Transfer Programs </li></ul></ul><ul><ul><ul><li>ftp (insercure; cannot be used at UW) </li></ul></ul></ul><ul><ul><ul><li>O:unixiws&lt;username&gt; </li></ul></ul></ul><ul><ul><ul><li>Secure file transfer (from C&amp;C) http://www.washington.edu/computing/ </li></ul></ul></ul><ul><ul><ul><li>software/uwick/contents.html </li></ul></ul></ul>
    • 3. Logging In <ul><li>Which server you use (almost) doesn’t matter – all four allows access to your files </li></ul><ul><li>Although your Windows and Unix usernames (and passwords) are the same, they are two separate accounts </li></ul><ul><ul><li>Your z: drive is not your Unix account </li></ul></ul><ul><li>Connecting: </li></ul><ul><ul><li>We’ll connect to the Unix machines via ssh </li></ul></ul><ul><ul><li>After connection, you are presented with a login prompt </li></ul></ul><ul><ul><li>After logging in, you’re placed in your home directory (where your personal files are located) </li></ul></ul>
    • 4. The Command Prompt <ul><li>Commands are the way to “do things” in Unix </li></ul><ul><li>A command consists of a command name and options called “flags” </li></ul><ul><li>Commands are typed at the command prompt </li></ul><ul><li>In Unix, everything (including commands) is case-sensitive </li></ul>[prompt]$ &lt;command&gt; &lt;flags&gt; &lt;args&gt; attu1:/u15/awong$ ls –l -a unix-tutorial Command Prompt Command (Optional) flags (Optional) arguments Note : In Unix, you’re expected to know what you’re doing. Many commands will print a message only if something went wrong.
    • 5. Two Basic Commands <ul><li>The most useful commands you’ll ever learn: </li></ul><ul><ul><li>man (short for “ man ual”) </li></ul></ul><ul><ul><li>info </li></ul></ul><ul><li>They help you find information about other commands </li></ul><ul><ul><li>man &lt;cmd&gt; or info &lt;cmd&gt; retrieves detailed information about &lt;cmd&gt; </li></ul></ul><ul><ul><li>man –k &lt;keyword&gt; searches the man page summaries (faster, and will probably give better results) </li></ul></ul><ul><ul><li>man –K &lt;keyword&gt; searches the full text of the man pages </li></ul></ul>fiji:/u15/awong$ man –k password passwd (5) - password file xlock (1) - Locks the local X display until a password is entered fiji:/u15/awong$ passwd
    • 6. Two Basic Commands (info) <ul><li>Info, as opposed to man, is category based </li></ul><ul><li>Documents are hyperlinked </li></ul><ul><ul><li>info &lt;cmd&gt; retrieves detailed information about &lt;cmd&gt; </li></ul></ul><ul><ul><li>info by itself will give instructions on its usage </li></ul></ul><ul><ul><li>Type q to quit . </li></ul></ul><ul><ul><li>Type h for help . </li></ul></ul>
    • 7. Directories <ul><li>In Unix, files are grouped together in other files called directories , which are analogous to folders in Windows </li></ul><ul><li>Directory paths are separated by a forward slash: / </li></ul><ul><ul><li>Example: /u10/hctang/classes/cse326 </li></ul></ul><ul><li>The hierarchical structure of directories (the directory tree) begins at a special directory called the root , or / </li></ul><ul><ul><li>Absolute paths start at / </li></ul></ul><ul><ul><ul><li>Example: /u10/hctang/classes/cse326 </li></ul></ul></ul><ul><ul><li>Relative paths start in the current directory </li></ul></ul><ul><ul><ul><li>Example: classes/cse326 (if you’re currently in /u10/hctang ) </li></ul></ul></ul><ul><li>Your home directory is where your personal files are located, and where you start when you log in. </li></ul><ul><ul><li>Example: /u10/hctang </li></ul></ul>
    • 8. Directories (cont’d) <ul><li>Handy directories to know </li></ul><ul><ul><li>~ Your home directory </li></ul></ul><ul><ul><li>.. The parent directory </li></ul></ul><ul><ul><li>. The current directory </li></ul></ul><ul><li>ls </li></ul><ul><ul><li>L i S ts the contents of the specified directories (or the current directory if no files are specified) </li></ul></ul><ul><ul><li>Syntax: ls [&lt;file&gt; … ] </li></ul></ul><ul><ul><li>Example: ls backups </li></ul></ul><ul><li>pwd </li></ul><ul><ul><li>P rint W orking D irectory </li></ul></ul>
    • 9. Directories (cont’d further) <ul><li>cd </li></ul><ul><ul><li>C hange D irectory (or your home directory if unspecified) </li></ul></ul><ul><ul><li>Syntax: cd &lt;directory&gt; </li></ul></ul><ul><ul><li>Examples: </li></ul></ul><ul><ul><ul><li>cd backups/unix-tutorial </li></ul></ul></ul><ul><ul><ul><li>cd ../class-notes </li></ul></ul></ul><ul><li>mkdir </li></ul><ul><ul><li>M a K e DIR ectory </li></ul></ul><ul><ul><li>Syntax: mkdir &lt;directories&gt; </li></ul></ul><ul><ul><li>Example: mkdir backups class-notes </li></ul></ul><ul><li>rmdir </li></ul><ul><ul><li>R e M ove DIR ectory, which must be empty </li></ul></ul><ul><ul><li>Syntax: rmdir &lt;directories&gt; </li></ul></ul><ul><ul><li>Example: rmdir backups class-notes </li></ul></ul>
    • 10. Files <ul><li>Unlike Windows, in Unix file types (e.g. “executable files, ” “data files,” “text files”) are not determined by file extension (e.g. “foo.exe”, “foo.dat”, “foo.txt”) </li></ul><ul><li>Thus, the file-manipulation commands are few and simple … </li></ul><ul><li>Many commands only use 2 letters </li></ul><ul><li>rm </li></ul><ul><ul><li>R e M oves a file, without a possibility of “undelete!” </li></ul></ul><ul><ul><li>Syntax: rm [options] &lt;file(s)&gt; </li></ul></ul><ul><ul><li>Example: rm tutorial.txt backups/old.txt </li></ul></ul><ul><ul><li>-r option: recursive (delete directories) </li></ul></ul><ul><ul><li>-f option: force. Do no matter what </li></ul></ul>
    • 11. Files (cont’d) <ul><li>cp </li></ul><ul><ul><li>C o P ies a file, preserving the original </li></ul></ul><ul><ul><li>Syntax: cp [options] &lt;sources&gt; &lt;destination&gt; </li></ul></ul><ul><ul><li>Example: cp tutorial.txt tutorial.txt.bak </li></ul></ul><ul><ul><li>-r option: recursive (copies directories) </li></ul></ul><ul><li>mv </li></ul><ul><ul><li>M o V es (renames) a file or directory, destroying the original </li></ul></ul><ul><ul><li>Syntax: mv [options] &lt;sources&gt; &lt;destination&gt; </li></ul></ul><ul><ul><li>Examples: </li></ul></ul><ul><ul><ul><li>mv tutorial.txt tutorial.txt.bak </li></ul></ul></ul><ul><ul><ul><li>mv tutorial.txt tutorial-slides.ppt backups/ </li></ul></ul></ul>Note : Both of these commands will over-write existing files without warning you!
    • 12. Permissions for files <ul><li>Files are owned by both a user and a group </li></ul><ul><li>You will either belong to ugrad_cs or ugrad_ce </li></ul><ul><li>Each file has 3 sets of permissions </li></ul><ul><ul><li>Permissions for the user who owns it (user permissions) </li></ul></ul><ul><ul><li>Permissions for the group that owns it (group permissions) </li></ul></ul><ul><ul><li>Permissions for everyone else (‘other’ or ‘world’ permissions) </li></ul></ul><ul><li>There are 3 types of permissions </li></ul><ul><ul><li>Read -- controls ability to read a file </li></ul></ul><ul><ul><li>Write -- controls ability to write or change a file </li></ul></ul><ul><ul><li>Executable -- controls whether or not a file can be executed as a program </li></ul></ul>
    • 13. Permissions for files (example) To see the permissions on a file, do a ‘ ls –l ’ attu4:/u15/awong$ ls –l -r--r--r-- 1 awong ugrad_ce 17375 Apr 26 2000 rgb.txt -rw-r--r-- 1 awong ugrad_ce 17375 Apr 5 02:57 set10.csv drwxr-xr-- 1 awong ugrad_ce 1024 Jan 19 19:39 tests Changing Permissions chmod [ugo]+[rxw] &lt;filename&gt; e.g. chmod u+w rgb.txt  gives me permission to change rgb.txt Changing Ownership chown &lt;user&gt;.&lt;group&gt; &lt;filename&gt; e.g. chmod awong.iuns rgb.txt  iuns group now owns rgb.txt Note: You cannot change which user owns file, unless you are an administrator, for security reasons.
    • 14. Permissions on directories <ul><li>Directories can also be thought of as a file that lists all the files it contains. </li></ul><ul><li>They also belong to a user and a group </li></ul><ul><li>They have the same 3 sets of permissions </li></ul><ul><li>For directories, this is what the permissions mean </li></ul><ul><ul><li>Read -- You can read the list of files (eg. You can use “ls” and get the directory contents) </li></ul></ul><ul><ul><li>Write -- You can change the list of files (eg. You can add or remove files from the directory) </li></ul></ul><ul><ul><li>Executable -- You can use the directory list to let the operating system “find” the file. This means, you have access to the file. All directories generally have execute permission. </li></ul></ul>
    • 15. Permissions Quiz <ul><li>Given the following output for ‘ ls –la ~ ’ for user awong.ugrad_ce </li></ul><ul><li>attu4:/u15/awong$ ls –la ~ </li></ul><ul><li>drwxr----x 1 awong ugrad_ce 1024 Jan 19 19:39 . </li></ul><ul><li>drwxr-xr-x 1 root root 17375 Apr 26 2000 .. </li></ul><ul><li>-rw-r--r-- 1 awong ugrad_ce 17375 Apr 5 02:57 readme.txt </li></ul><ul><li>-rw-rwxr-x 1 awong ugrad_ce 17375 Apr 5 02:57 myprog </li></ul><ul><li>For users ethel.ugrad_ce, jjlin@ugrad_cs, and awong.ugrad_ce: </li></ul><ul><li>Who can create files in this directory? </li></ul><ul><li>Who can get the list of files in this directory? </li></ul><ul><li>Who can read the contents of the files readme.txt? How about myprog? Who can run the program “myprog”? </li></ul><ul><li>What is dangerous about the permissions on myprog? Especially the ‘.’ directory had g+w access? </li></ul><ul><li>Can you think of a reason why you would give someone execute, but not read permissions on a directory? How read but not execute? </li></ul>
    • 16. Shell Shortcuts <ul><li>Tab completion </li></ul><ul><ul><li>Type part of a file/directory name, hit &lt;tab&gt; , and the shell will finish as much of the name as it can </li></ul></ul><ul><ul><li>Works if you’re running tcsh or bash </li></ul></ul><ul><li>Command history </li></ul><ul><ul><li>Don’t re-type previous commands – use the up-arrow to access them </li></ul></ul><ul><li>Wildcards </li></ul><ul><ul><li>Special character(s) which can be expanded to match other file/directory names </li></ul></ul><ul><ul><li>* Zero or more characters </li></ul></ul><ul><ul><li>? Zero or one character </li></ul></ul><ul><ul><li>Examples: </li></ul></ul><ul><ul><ul><li>ls *.txt </li></ul></ul></ul><ul><ul><ul><li>rm may-?-notes.txt </li></ul></ul></ul>
    • 17. Editing Text <ul><li>Which text editor is “the best” is a holy war. Pick one and get comfortable with it. </li></ul><ul><li>Three text editors you should be aware of: </li></ul><ul><ul><li>pico – Comes with pine ( Dante ’s email program) </li></ul></ul><ul><ul><ul><li>To quit: Ctrl-q </li></ul></ul></ul><ul><ul><li>emacs/xemacs – A heavily-featured editor commonly used in programming </li></ul></ul><ul><ul><ul><li>To quit: Ctrl-x Ctrl-c </li></ul></ul></ul><ul><ul><li>vim/vi – Another editor, also used in programming </li></ul></ul><ul><ul><ul><li>To quit: &lt;Esc&gt; : q &lt;Enter&gt; (or QQ -- capitals matter) </li></ul></ul></ul>Knowing the basics of emacs and vim will help with the rest of Unix; many programs have similar key sequences.
    • 18. Printing <ul><li>READ THE MORE UPDATED PRINTING TUTORIAL: </li></ul><ul><ul><li>http://www.cs.washington.edu/orgs/acm/tutorials/printing </li></ul></ul><ul><li>Printing: </li></ul><ul><ul><li>lpr : print </li></ul></ul><ul><ul><ul><li>Use –h (no header) and –Zduplex (double-sided) to save paper </li></ul></ul></ul><ul><ul><li>lpq : check the print queue (including Windows print jobs!) </li></ul></ul><ul><ul><li>lprm : remove print jobs (including Windows print jobs) </li></ul></ul><ul><ul><li>For the above commands, you will need to specify the printer with the option: –P&lt;printer name&gt; </li></ul></ul><ul><li>Check out enscript (quizlet: how do you find information about commands?) to print text files nicely! </li></ul><ul><ul><li>WARNING: Do NOT use enscript with postscript files! </li></ul></ul>
    • 19. Programs and Compilation (C++) <ul><li>To compile a program: </li></ul><ul><ul><li>g++ &lt;options&gt; &lt;source files&gt; </li></ul></ul><ul><ul><li>Recommended: g++ -Wall –ansi –o &lt;executable_name&gt; *.cpp </li></ul></ul><ul><ul><ul><li>-Wall – W arnings: ALL </li></ul></ul></ul><ul><ul><ul><li>-ansi – Strict ANSI compliance </li></ul></ul></ul><ul><ul><ul><li>Quizlet: what does *.cpp mean? </li></ul></ul></ul><ul><li>What’s an “executable”? </li></ul><ul><ul><li>In Windows, double-clicking on an icon runs a program </li></ul></ul><ul><ul><ul><li>E.g. double-click on C:Windows otepad.exe </li></ul></ul></ul><ul><ul><li>In Unix, you can run your executable from the command line! </li></ul></ul><ul><ul><ul><li>Type the executable name at the prompt, just like a command </li></ul></ul></ul><ul><ul><ul><ul><li>In fact, commands are actually executables </li></ul></ul></ul></ul><ul><ul><ul><li>However, you may need to specify the path to your executables </li></ul></ul></ul><ul><ul><ul><ul><li>./&lt;program&gt; runs &lt;program&gt; in the current directory </li></ul></ul></ul></ul><ul><ul><ul><li>Example: </li></ul></ul></ul><ul><ul><ul><ul><li>attu4:ehsu% g++ -Wall –ansi –o hello hello.cpp </li></ul></ul></ul></ul><ul><ul><ul><ul><li>attu4:ehsu% ./ hello </li></ul></ul></ul></ul>
    • 20. Programs and Compilation (Java) <ul><li>To compile a program: </li></ul><ul><ul><li>javac fileName1.java filename2.java . . . </li></ul></ul><ul><ul><li>Errors will be printed to the screen with their line numbers </li></ul></ul><ul><ul><li>Remember that the class name must have the same capitalization as the file name </li></ul></ul><ul><ul><li>To compile all the .java files in the current folder: </li></ul></ul><ul><ul><ul><li>javac *.java </li></ul></ul></ul><ul><li>To run : </li></ul><ul><ul><li>java classname (remember, no .java or .class) </li></ul></ul><ul><ul><li>This will run the main method for that class. </li></ul></ul>
    • 21. X-Windows <ul><li>X-Windows is the most common graphical interface for Unix </li></ul><ul><li>It allows graphics to be sent over the network (Windows Remote Desktop is similar to this) </li></ul><ul><li>If you login via the ssh-x shortcuts, you will start and “X-server” on your machine and you will be able to get graphics from your unix commands </li></ul><ul><li>If you log into a linux box, you will automatically have X-windows setup in that login. </li></ul>
    • 22. Linux Machines, iuns <ul><li>Linux Machines: </li></ul><ul><li>There are 6 linux machines in each lab </li></ul><ul><li>The graphics work smoother on those machines </li></ul><ul><li>Be sure to get a good “Window Manager” setup </li></ul><ul><li>Ask one of the other people using the linux boxes for help setting up your window manager. </li></ul><ul><li>Iuns: </li></ul><ul><li>Iuns is the “instruction unsupported” software group </li></ul><ul><li>Student volunteers maintain cutting edge software for unix and windows </li></ul><ul><li>E-mail [email_address] for more info </li></ul>

    ×