net prog1-shell1-1

24

Upload: maria-sawaby-nazehat

Post on 12-Feb-2017

120 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Net prog1-shell1-1

Technical Foundation of Computer Science 5

Network Programming I

Maria Sawaby

Department of Communication and Operating System

February 9, 2015

Net-Dep (Network) Net-Prog I February 9, 2015 1 / 24

Page 2: Net prog1-shell1-1

Contents

1 Introduction

2 Linux Distributions

3 File System Structure

4 The shell

5 BASH

6 The Shell Prompt

7 Bash Characters

8 The bash Manual

9 Traversing Directory

10 File and Directory Listing

11 Filtering listing output

12 Summary

Net-Dep (Network) Net-Prog I February 9, 2015 2 / 24

Page 3: Net prog1-shell1-1

UNIX Introduction

UNIX is an operating system designed for use on any kind of computer

features:I multi-user and multi-taskingI GUII Hierarchical �lesystemI portabilityI text based con�guration �les

Types of UNIX:

many di�erent version of unix, sharing common similaritiesI GNU/LinuxI Sun SolarisI Mac OSI BSD

Net-Dep (Network) Net-Prog I February 9, 2015 3 / 24

Page 4: Net prog1-shell1-1

Linux Distributions

Linux distributions:I UbuntuI FedoraI DebianI Linux MintI OpenSuseI ...

Net-Dep (Network) Net-Prog I February 9, 2015 4 / 24

Page 5: Net prog1-shell1-1

File System Structure

Directory Hierarchy:

Net-Dep (Network) Net-Prog I February 9, 2015 5 / 24

Page 6: Net prog1-shell1-1

Directory Hierarchy:

1 / Root

2 /bin - User Binaries

3 /sbin - System Binaries

4 /etc - Con�guration Files

5 /dev - Device Files

6 /proc - Process Information

7 /var - Variable Files

8 /tmp - Temporary Files

9 /usr - User Programs

10 /home - Home Directories

11 /boot - Boot Loader Files

12 /lib - System Libraries

13 /opt - Optional add-onApplications

14 /mnt - Mount Directory

15 /media - Removable MediaDevices

16 /srv - Service Data

17 ...

Net-Dep (Network) Net-Prog I February 9, 2015 6 / 24

Page 7: Net prog1-shell1-1

What is a command shell?

A program that interprets commands

Allows a user to execute commands by typing them manually at aterminal, or automatically in programs called shell scripts

The shell of linux

Linux has a variety of di�erent shells:

I Bourne shell (sh)I C shell (csh)I Korn shell (ksh)I TC shell (tcsh)I Bourne Again shell (bash)

F Certainly the most popular shell is �bash�F Bash incorporates useful features from the Korn shell (ksh) and C shell

(csh)

Net-Dep (Network) Net-Prog I February 9, 2015 7 / 24

Page 8: Net prog1-shell1-1

what is bash?

bash is not only an excellent command line shell, but a scriptinglanguage in itself

Shell scripting allows us to use the shell's abilities and to automate alot of tasks that would otherwise require a lot of commands

It runs as a regular program, normally started whenever a user logs into a terminal

The shell that the system starts depends on your user ID con�guration

/etc/passwd �le contains a list of all the system user accounts

Net-Dep (Network) Net-Prog I February 9, 2015 8 / 24

Page 9: Net prog1-shell1-1

what is bash?

a sample entry from /etc/passwd �lemaria:x:1000:1000:Maria� ,:/home/maria:/bin/bash-user name-user's password-user's system user ID number-user's system group ID number-user's full name-user's default home directory-user's default shell program

Net-Dep (Network) Net-Prog I February 9, 2015 9 / 24

Page 10: Net prog1-shell1-1

The Shell Prompt

Once you start a terminal or log in from the Linux console, you getaccess to the shell CLI prompt

The prompt is your gateway to the shell where you enter shellcommands

The default prompt symbol for the bash shell is the dollar sign ($)

The di�erent Linux distributions use di�erent formats for the prompt

example: on my ubuntu system

maria@cs:∼$ (username, hostname, home directory (∼))

Net-Dep (Network) Net-Prog I February 9, 2015 10 / 24

Page 11: Net prog1-shell1-1

Controlling Shell Prompt

You can control the format of the command line prompt using PS1

PS1 displays the following three information in the promptI \u - UsernameI \h - HostnameI \w - Full path of the current working directory

examples: (You can use the export command to make local variablesglobal)

Net-Dep (Network) Net-Prog I February 9, 2015 11 / 24

Page 12: Net prog1-shell1-1

Controlling Shell Prompt

Net-Dep (Network) Net-Prog I February 9, 2015 12 / 24

Page 13: Net prog1-shell1-1

bash prompt characters

Net-Dep (Network) Net-Prog I February 9, 2015 13 / 24

Page 14: Net prog1-shell1-1

The bash Manual

Most Linux distributions include an online manual for looking upinformation on shell commandsThe man command provides access to the manual pages stored on theLinux system (e.g. $man date)

Net-Dep (Network) Net-Prog I February 9, 2015 14 / 24

Page 15: Net prog1-shell1-1

Net-Dep (Network) Net-Prog I February 9, 2015 15 / 24

Page 16: Net prog1-shell1-1

Di�erences in File-systems

linux does not use drive letter

�le pathI (backslash) \ in windows:

c:\Documents and Settings\Maria\My Documents\lec-1.doc

I (forward slash) / in linux:

/home/maria/Documents/lec-1.odt

Net-Dep (Network) Net-Prog I February 9, 2015 16 / 24

Page 17: Net prog1-shell1-1

Traversing directories

The cd command is used to move the shell session to another directory

The cd command may take a single parameter, destinationcd Desktop

Two methods to destination parameter:1 An absolute �lepath2 A relative �lepath

Net-Dep (Network) Net-Prog I February 9, 2015 17 / 24

Page 18: Net prog1-shell1-1

Absolute Filepath

The absolute �lepath de�nes exactly where the directory is in thevirtual directory structure

Example:

maria@cs:∼$ cd /home/maria/Desktop/route/

Net-Dep (Network) Net-Prog I February 9, 2015 18 / 24

Page 19: Net prog1-shell1-1

Relative �lepath

Relative �lepaths allow you to specify a destination �lepath relative toyour current location, with out having to start at the root

A relative �lepath doesn't start with a forward slash

relative �lepath starts with either a directory name, or a specialcharacter indicating a relative location to your current directorylocation

The two special characters used for this are:I The dot (.) to represent the current directoryI The double dot (..) to represent the parent directory

Example:

Net-Dep (Network) Net-Prog I February 9, 2015 19 / 24

Page 20: Net prog1-shell1-1

Basic Listing

ls (list �les and dirs)

ls

ls -a (Show all + hidden)

ls -F (Flags Directories with forward slash)

ls -F -R (Shows �les that are within directories in the current directory)

Net-Dep (Network) Net-Prog I February 9, 2015 20 / 24

Page 21: Net prog1-shell1-1

Basic Listing

ls -l shows the following information about each �le or directory:I �le typeI permissions for the �leI number of hard links to the �leI username of the owner of the �leI group name of the group the �le belongs toI size of the �le in bytesI time the �le was modi�ed lastI �le or directory name

Net-Dep (Network) Net-Prog I February 9, 2015 21 / 24

Page 22: Net prog1-shell1-1

the ls command also provide a way for us to de�ne a �lter on thecommand line

Sometimes you might not know the exact name of the �le you'relooking for,so use:

I A question mark (?) to represent one characterI An asterisk (*) to represent zero or more characters

Net-Dep (Network) Net-Prog I February 9, 2015 22 / 24

Page 23: Net prog1-shell1-1

Summary

Linux distributions

File system structure

The Shell

Bash and Bash Manual

Working on �les and Directories

Net-Dep (Network) Net-Prog I February 9, 2015 23 / 24

Page 24: Net prog1-shell1-1

Net-Dep (Network) Net-Prog I February 9, 2015 24 / 24