Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS240 Computer Science II Introduction the Unix File System and File Related Utilities Based on “UNIX for Programmers and Users” by G.Class and K. Ables.

Similar presentations


Presentation on theme: "CS240 Computer Science II Introduction the Unix File System and File Related Utilities Based on “UNIX for Programmers and Users” by G.Class and K. Ables."— Presentation transcript:

1 CS240 Computer Science II Introduction the Unix File System and File Related Utilities Based on “UNIX for Programmers and Users” by G.Class and K. Ables

2 Obtaining an account Obtaining username (login name) and password from the instructor Username: the department usually your last name and the first character of your first name as your login name. For example, doej is the username for Doe, John Password: your social security number (9 digits without blanks or hyphens. The password can be changed with the passwd command.

3 Logging in telnet cs.wpunj.edu At the prompts, enter –Enter username –Enter password If your are accessing the system from your home (assume you have internet access) –Connect to the internet –Click Start button on the task bar (Window) –Select and click “Run” command –Type telnet cs.wpunj.edu –Enter username and password

4 Unix shells and shell commands Shell is an interface between the user and the kernel of the Unix OS The shell usually displays a prompt character $ or % after you logged in. There are three popular shells: –The Bourne shell –The Korn shell (a superset of the Bourne shell) –And the C shell All shells share a same set of core functionality together with some specialized properties.

5 Programmability with shells Each shell has its own programming languages which are tailored to manipulating files and processes in the Unix system. Shell programming are covered in later chapters of the book.

6 Running a utility program Recalling from previous lecture, standard Unix comes with at least 200 utility programs including, compilers, text processing tools, spreadsheets, desk-top publishing, sorting utility, some shells programs, graphical user interface (GUI), etc. To run a utility program, simply enter the name of the program and press enter key, e.g., $ date displays date and time. Notice that the names are case- sensitive!

7 Some frequently used utilities and their basic functions man - displays manual pages stty - displays terminal characteristics passwd – changing password pwd – displays current directory vi, pico, emacs – starts the vi or emacs editor cat, more, page, head, or tail – displays the contents of a file ls – lists all of the files in the current working direct Rory in alphabetical order mv – renaming or moving a file mail and xmail – allows one to send and read e-mails

8 Some frequently used utilities and their basic functions mkdir – creates a new directory rmdir – removes an existing directory cd – changes to a different directory cp – copies a file rm – deletes a file lp, lpstat, cancel – relates to file printing wc – counts # lines, words, and/or characters in a file file – attempts to describe the contents of the file chmod – allows the user to control the accessibility of a file group – displays a list of groups that you are a member of

9 Unix file structure: directory, subdirectory, relative path name, absolute path name Hierarchical (inverted tree) structure Root directory: / Working directory: your default login directory (pwd displays it) Absolute pathname that specifies the location of a file: traces all the way from the root directory to where the file is located. Relative pathname: pathname relative to the current working directory.

10 A brief summary of file manipulating utilities

11

12 The ls utility and file attributes

13 The chmod and the file permissions P42/43/46/47

14 Some important key strokes ^ means holding down the Ctrl key ^S – freezes the scrolling of screen display ^Q – resumes the scrolling of screen display ^D – signifies to the Unix the end of input (e.g., after you finished typing your e-mail) ^D – if entered at a shell prompt such as $, it requests the Unix the end the session.

15 The vi (visual) Full-Page Editor Two mode –The command mode: allow command to be entered –Text-entry or input mode: enter text (e.g., C++ program instructions)

16 Common vi editing features Cursor movement Deleting text Replacing text Pasting text Searching/replacing text Saving/loading files miscellaneous

17 Cursor movement commands p58

18 vi text deleting commands p58

19 From command mode to text-entry mode When vi is started, it enters into the command mode. To switch to the text-entry mode enter any of the following keys (p55):

20 From text-entry mode to command mode Simply press the esc key

21 Modes in vi: a diagram

22 C/C++ Programming Tools Common tools C/C++ compiler(s) The make utility Source code management systems –sccs (source code control system) –rcs (revision control system) The debugging utilities –lint –Adb, sdb, and debug

23 How to create, compile, and execute a C/C++ program Use an editor such as vi to create and save a program Use a compiler to compile a program $ cc example1.c or $ g++ example2.cpp After successful compilation, the linker creates an executable file a.out To run the executable file, simply type a.out at the command line

24 Compilation options -l (lower-case L) to specify the libraries $ cc calc.c –lm (uses abbr for library name; m stands for libm.a or math library) -O causes the compiler to use the optimizer -c suppresses the link-edit process (useful to test an individual module) -o gives the executable (by default a.out) the name of your choice $ cc –o example calc.c (example replaces a.out as the name of the executable file. Note that without using –o option, you can always use mv to rename a.out as in $ mv a.out example)

25 Multiple file compilation If there is only one object file, cc removes it after it successfully creates the a.out. But if there are multiple object files (with.o extensions), all object files are retained. $ cc ledger.c acctspay accstrec.c (3 source files) $ ls a.out acctspay.o acctsrec.o ledger.o acctspay.c acctsrec.c ledger.c

26 More on header files and the #include preprocessor directive When several symbolic constants, macros, and class definitions are used in different modules of a program, they are typically collected together in a single file called header file (or include file). The angle bracket ( ) instructs the preprocessor to look for the header file in a standard directory (/usr/include on most systems). If you want to include header file in another directory, use double quotes and specify the appropriate pathname of the file such as #include “/home/alex/cs240/myheader.h”

27 Using lint to find errors lint is one of the most useful debugging tools. It checks programs for potential bugs and portability problems. It it much more strict than C/C++ compiler. The following line shows the syntax of how it is used. $ lint example.c The above line will print warning and errors in the program named example.c.

28 The standard input/output devices Standard input: keyboard Standard output: monitor Device drivers (files) are stored in /dev directory, which allow devices to be treated as files. By default, keyboard and monitor are assumed as the standard I/O devices, e.g., $ a.out runs the executable file a.out. If a.out requires input, the input will come from the keyboard; if a.out produces output, the output will be displayed on the screen.

29 Input and output redirection > means redirecting the output to < means obtaining the input from For example: $ a.out < indata (reads data from indata file and displays results on the screen) $ a.out > outresult (reads data from the keyboard and sends results to outresult file) $ a.out outresult (reads data from indata and displays results on the screen) Note that a.out can be replaced by any executable command or utility program.


Download ppt "CS240 Computer Science II Introduction the Unix File System and File Related Utilities Based on “UNIX for Programmers and Users” by G.Class and K. Ables."

Similar presentations


Ads by Google