1 / 17

Unix Primer

Unix Primer. Unix Shell. The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular” program. It displays a prompt, waits for user input, and interprets the command line entered by the user.

isra
Télécharger la présentation

Unix Primer

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Unix Primer

  2. Unix Shell • The shell is a command programming language that provides an interface to the UNIX operating system. • The shell is a “regular” program. It displays a prompt, waits for user input, and interprets the command line entered by the user. • It goes back to the prompt again after interpreting a command line • There are several different shells available, such as bsh, csh, tcsh, etc. • We will be using the shell on UCFileSpace (Bourne-again shell or Bash)

  3. Accessing Unix shell in this course • Go to https://ucfilespace.uc.edu/ • Search for Unix • A description of accessing the Unix shell is given on Ucfilespace: • On Windows, PuTTY: https://ucfilespace.uc.edu/wiki/search/109 • On Mac, using ssh command: https://ucfilespace.uc.edu/wiki/search/108

  4. Editors • Vim For Vim tutorial type on command line vimtutor • Emacs For Emacs tutorial, while in Emacs type <ctrl-h> t • for reference cards on Emacs and Vim See Supporting Material on CascadeLMS https://cascade.ceas.uc.edu/

  5. Directories The shell should start you in your home directory. This is your individual space on the UNIX system for your files. You can find out the name of your current working directory by typing: pwd The system normally will display : /Users/username Change to a sub-directory “sub” by typing: cd sub No matter where in the directory structure you are, you can always get back to your home directory by typing: cd(without specifying a directory name). From your home directory, create a new subdirectory named "primer" for working through this tutorial: mkdir primer You can remove an empty subdirectory with the following command (but don't do this right now): rmdir primer Now change to the "primer" subdirectory, making it your current working directory: cd primer

  6. Files (1) Since you just created the directory “primer”, nothing will be listed because the directory is empty. Create your first file called first using the Emacs or Vim text editor to type in text: My name is Joe Doe. This is my first file. Now when you list your files, you will see file "first" listed: lsfirst You can view a text file with the following command: cat firstMy name is Joe Doe. This is my first file. ("cat" is short for concatenate - you can use this to display multiple files together on the screen.) If you have a file that is longer than your 24-line console window, use instead "more" to list one page at a time or "less" to scroll the file down and up with the arrow keys. Don't use these programs to try to display binary (non-text) files on your console - the attempt to print the non-printable control characters might alter your console settings and render the console unusable.

  7. Files (2) Copy file "first" using the following command: cp first 2ndBy doing this you have created a new file named "2nd" which is a duplicate of file "first". The file listing reveals: ls2nd first Now rename the file "2nd" to "second": mv 2nd secondListing the files still shows two files because you haven't created a new file, just changed an existing file's name: lsfirst second If you "cat" the second file, you'll see the same sentence as in your first file: cat secondMy first file. "mv" will allow you to move files, not just rename them. Perform the following commands: mkdir sub mv second sub ls subsecond lsfirst sub

  8. Files (3) You can list even more information about files by using the "-l" option with "ls": ls -l-rw-r--r-- 1 username group 15 Jan 4 16:26 firstdrwxr-xr-x 2 username group 512 Jan 4 17:11 sub(where "username" will be your username and "group" will be your group name). Among other things, this lists the creation date and time, file access permissions, and file size in bytes. The letter 'd' (the first character on the line) indicates the directory names. Next perform the following commands: cd sub pwd/Users/username/primer/sub ls -l-rw-r--r-- 1 username group 4 Jan 4 16:55 second cd .. pwd/Users/username/primer Finally, clean up the duplicate files by removing the "second" file and the "sub" subdirectory: rm sub/second rmdir sub ls -l-rw-r--r-- 1 username group 15 Jan 4 16:26 first

  9. Online manual man - command for online manual

  10. Path Names dir name + file name • Absolute pathname: starting from root • E.g. /user/doej/bin/myProg.cpp • Relative pathname myProg.cpp (a file under current dir) bin/myProg.cpp (a file under subdir “bin” of current dir • The system maintains a “current working directory”, and will prefix it to a relative pathname

  11. Special Directories • The first two members of any subdirectories are two special directories “.” and “..” • “.” : self • Will show how to use it • “..”: parent dir E.g.: cd .. • Go to the parent directory pwd sub1 cd ../sub2

  12. Source Code Naming Convention .cpp : C++ source code file

  13. How to use GNU C++ compiler/linker g++ g++ myProg.cpp Compiles myProg.cpp, generates an object file, link the object file (with libraries), and generates an executable file called “a.out”. g++ myProg.cpp –o myProg Same as above, however the executable has a name “myProg”

  14. How to execute your program • Find the executable from the current directory, and run it • Unix can take any file extension as executable • Does not have to use a “.exe” extension name • As long as the file is marked as executable For example, using default name a.out for executable, enter on command line: uc ./a.out DON’T forget ./ to indicate current directory

  15. Redirection of Input and Output • < filename take standard input from that filename • > filename send standard output to filename • Examples: ls > myfiles more < myfiles cat < myfiles > myfilesoutput

  16. The UNIX pipe • ls | more • Same as ls > temp more < temp rm temp

More Related