Top Banner
CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles
23

CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Jan 19, 2016

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

CS 245 – Part 1 Using Operating Systems and Networks

for Programmers

Jiang GuoDept. of Computer Science

California State University Los Angeles

Page 2: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Where to Start

Available UNIX: mars, neptune, juniper, …in CSULA campus

You have to have an account first through submitting an application (Library).

Login name + Password Use telnet to login. There are several

different kind of telnet. You also can install Linux at home (if

dual boot, windows first).

Page 3: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Telnet

C>telnet mars.calstatela.edu C>telnet neptune.calstatela.edu, … Start Run telnet

mars.calstatela.edu Program SSH Secure Shell

Secure Shell Client. MochaSoft Telnet ………..

Page 4: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

The Shell

Shells provide the command line interface to UNIX (there are other types of interface)

Why learn the command line? The GUI isn't always available The command line is often more efficient The command line is often more powerful You must become familiar with using the

command line

Page 5: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Introduction to UNIX Commands

Command line format iscommand_name [ -switches ] [ parameter1 ] [ parameter2..]

There must be whitespace between each of these components

command_name the name of command to be executed (will match an executable file somewhere)

switches switches or options are used to modify the operation of a command.

parameter1 a list of parameters/arguments which will be passed to the command

Page 6: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Introduction to UNIX Commands

Examples include ls ls -l ls -l /etc /home ls -ld /etc /home

Page 7: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

The File Hierarchy

UNIX uses an upside down tree of directories for file storage.

For the Windows users: Files are documents, Directories are Folders

Page 8: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

The File Hierarchy

A file is a container for data, be it an image, text, a word processor file.

A directory is a collection of files. To UNIX a directory is just a file that

contains pointers to files. We will use file/directory

interchangably Each user has a home directory in

which they can do what they want.

Page 9: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Paths

Paths or path names are specifications of where to find a file/directory.

There are two types of paths absolute (full)

The path to the file is fully specified/home/…..

relativeThe path to the directory is relative to the current directory (The pwd command will tell you the current directory)../…

Page 10: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Paths

Directory and filenames are separated by / (can't be used in filenames)

Every directory contains at least two directories . the current directory .. the parent directory Try ls -al in any directory. Example neptune> ls -al total 1848 drwx--S--- 10 jguo 1024 Apr 23 12:02 . drwxr-sr-x 227 root 4096 Apr 7 10:26 .. -rw------- 1 jguo 500 Dec 16 22:05 .Xauthority -rw------- 1 jguo 221 Apr 17 12:29 .bash_history -rw------- 1 jguo 2205 Nov 13 2002 .cshrc

Page 11: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Important Directories

/bin binaries required when in single user mode /dev device files /etc System configuration files and scripts /home User home directories /lib Main OS shared libraries and kernel modules /sbin System administration binaries and tools /tmp Storage of temporary files /usr Contains almost everything else including

libraries, binaries, applications and packages /var Variable data, usually machine specific.

Including spool directories for mail and news. Also system logs and messages.

Page 12: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Moving around the file hierarchy cd command is used to change directories Examples 1. cd

Return to the home directory of the user. Can also use ~ as your home directory (at least in bash)

2. cd /Return to the root directory.

3. cd ..Change to the parent directory.

4. cd .Change to the current directory.

5. cd ../../../binMove to the bin directory which is up three directories

Page 13: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Commands are programs UNIX commands are actually executable programs stored

on the disk. This means you can write commands too! The shell

reads the command line you typed extracts out the name of the command looks for a file with a matching filename creates a new process using the code in that file

Common commands are stored in the bin directories: /bin /usr/bin /usr/local/bin /usr/X11R6/bin /sbin /usr/sbin

There are around hundreds commands. If you see the error messagedir: command not found

This means that the shell was unable to find the executable file with a name which matches the name of the command.

Page 14: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Help

We can't show you how to use all hundreds commands.

However, most of these commands have online documentation in the form of manual pages.

Manual (man) pages are a reference to individual commands. They can be difficult to read (take your time).

As with any manual, the manual pages are divided into sections

Page 15: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Help

Manual Section Description 1 User commands 2 System calls 3 Library functions

4 Special files 5 File formats 6 Games

Page 16: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

What are the man pages They are text files written using a special format.

(one file for each man page) Stored in subdirectories of the man directories

(/usr/man /usr/local/man) Written by people to provide assistance with

commands Displayed using the man command Examples

man ls man convert man man

Page 17: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Some Commands

date Display the current time and date who display who is currently on the

computer gcc/g++ C++/C compilers cal display a calendar wc count the number of characters,

words and lines cat display the contents of a file more and less display the contents of a

file a page at a time

Page 18: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Some Commands rm Remove a file cp Make a copy of a file mv Move a file or change the name of a file file Display the information of a file grep Search for a specific string in a file whereis Display the path of a utility program Which Display the path of a command finger Display detail information about users echo Display a line of text on the terminal Mail Send and receive emails write, talk, mesg Communicate each other

Page 19: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

vi

vi is an editor. It is the editor I strongly suggest you start using since you will be a professional software engineer.

Why? it's always available on UNIX it makes you look like professional it is hugely powerful

Page 20: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

Introduction to vi vi is a modal editor (two mode) command mode

The initial mode where most of the keys perform vi commands

insert modeThe mode where what you type is inserted into your document

command line mode Transitions

command mode to insert modeSeveral commands/keys put you into insert mode i a I A o O

insert mode to command modeHit the escape key

Page 21: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

vi Commands

23xDelete 23 characters

25ddDelete 25 lines

d$Delete from current position to the end of the line

Page 22: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

vi Command Line Commands

:wqWrite any changes and quit

:qQuit (will only do so if no changes)

:q!Quit without saving changes

http://www.eng.hawaii.edu/Tutor/vi.html

Page 23: CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.

PICO

pico is a full screen editor. It iseasy to learn and easy to use.