Outline. Log In & Log Out. System Information. CS4233 Network Programming Introduction to UNIX. UNIX commands Editors

Similar documents
Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, Introduction 1. 2 Invoking Shell Scripts 2

Unix Scripts and Job Scheduling

Fred Hantelmann LINUX. Start-up Guide. A self-contained introduction. With 57 Figures. Springer

Thirty Useful Unix Commands

Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script

Cisco Networking Academy Program Curriculum Scope & Sequence. Fundamentals of UNIX version 2.0 (July, 2002)

HP-UX Essentials and Shell Programming Course Summary

Command Line - Part 1

Command Line Crash Course For Unix

Unix Sampler. PEOPLE whoami id who

Tutorial 0A Programming on the command line

USEFUL UNIX COMMANDS

An A-Z Index of the Apple OS X command line (TERMINAL) The tcsh command shell of Darwin (the open source core of OSX)

An Introduction to the Linux Command Shell For Beginners

ICS 351: Today's plan

Hands-On UNIX Exercise:

CS2720 Practical Software Development

Linux command line. An introduction to the Linux command line for genomics. Susan Fairley

AN INTRODUCTION TO UNIX

Linux System Administration on Red Hat

LSN 10 Linux Overview

Introduction to Mac OS X

SFTP SHELL SCRIPT USER GUIDE

Fundamentals of UNIX Lab Networking Commands (Estimated time: 45 min.)

Automating admin tasks using shell scripts and cron Vijay Kumar Adhikari.

A Crash Course on UNIX

A UNIX/Linux in a nutshell

Beginners Shell Scripting for Batch Jobs

Lecture 4: Writing shell scripts

Syntax: cd <Path> Or cd $<Custom/Standard Top Name>_TOP (In CAPS)

Bash shell programming Part II Control statements

Basic Linux & Package Management. Original slides from GTFO Security

Unix the Bare Minimum

CS Unix Tools & Scripting Lecture 9 Shell Scripting

UNIX / Linux commands Basic level. Magali COTTEVIEILLE - September 2009

Introduction to Shell Programming

LECTURE-7. Introduction to DOS. Introduction to UNIX/LINUX OS. Introduction to Windows. Topics:

Lab 1: Introduction to C, ASCII ART and the Linux Command Line Environment

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003

Birmingham Environment for Academic Research. Introduction to Linux Quick Reference Guide. Research Computing Team V1.0

Tutorial Guide to the IS Unix Service

HARFORD COMMUNITY COLLEGE 401 Thomas Run Road Bel Air, MD Course Outline CIS INTRODUCTION TO UNIX

Introduction to. UNIX Bob Booth December 2004 AP-UNIX2. University of Sheffield

Introduction to Linux and Cluster Basics for the CCR General Computing Cluster

Introduction to the UNIX Operating System and Open Windows Desktop Environment

Introduction to Operating Systems

New Lab Intro to KDE Terminal Konsole

TEL2821/IS2150: INTRODUCTION TO SECURITY Lab: Operating Systems and Access Control

Lecture 22 The Shell and Shell Scripting

Introduction to Shell Scripting

Unix Guide. Logo Reproduction. School of Computing & Information Systems. Colours red and black on white backgroun

Lab 1: Introduction to the network lab

UNIX, Shell Scripting and Perl Introduction

Hadoop Shell Commands

Hadoop Shell Commands

This presentation explains how to monitor memory consumption of DataStage processes during run time.

CPSC 2800 Linux Hands-on Lab #7 on Linux Utilities. Project 7-1

L01 Introduction to the Unix OS

UNIX Tutorial for Beginners

Unix/Linux Forensics 1

CS 103 Lab Linux and Virtual Machines

Systems Programming & Scripting

Linux Overview. Local facilities. Linux commands. The vi (gvim) editor

Command-Line Operations : The Shell. Don't fear the command line...

Basic Linux and Unix commands, editing and transfering files

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

The Linux Operating System and Linux-Related Issues

Secure Shell Demon setup under Windows XP / Windows Server 2003

OS9 UNIX help man chd cd del rm copy cp makdir mkdir OS9 is case sensitive!! attr chmod deldir rmdir pd pwd list more

List of FTP commands for the Microsoft command-line FTP client

Lecture 25 Systems Programming Process Control

CPSC2800: Linux Hands-on Lab #3 Explore Linux file system and file security. Project 3-1

Red Hat Linux Administration II Installation, Configuration, Software and Troubleshooting

CSIL MiniCourses. Introduction To Unix (I) John Lekberg Sean Hogan Cannon Matthews Graham Smith. Updated on:

How To Set Up A Network Map In Linux On A Ubuntu 2.5 (Amd64) On A Raspberry Mobi) On An Ubuntu (Amd66) On Ubuntu 4.5 On A Windows Box

Agenda. Using HPC Wales 2

HDFS File System Shell Guide

Tour of the Terminal: Using Unix or Mac OS X Command-Line

The Linux Operating System

UNIX - FILE SYSTEM BASICS

Outline. Unix shells Bourne-again Shell (bash) Interacting with bash Basic scripting References

Secure File Transfer Installation. Sender Recipient Attached FIles Pages Date. Development Internal/External None 11 6/23/08

BASH Scripting. A bash script may consist of nothing but a series of command lines, e.g. The following helloworld.sh script simply does an echo.

Higher National Unit Specification. General information for centres. Multi User Operating Systems. Unit code: DH3A 34

Unix Tools. Overview. Editors. Editors nedit vi Browsers/HTML Editors Mail Tools Utilities xv xman ftp

UNIX Basics. Ian Darwin TCP Informatics January, Presented from a Mac using Apple s Keynote presentation software

Answers to Even-numbered Exercises

Worksheet 3: Distributed File Systems

system or read a good Unix book from the DESY library (e.g. Mark Sobell, APractical Guide to

Intrusion Detection and Prevention: Network and IDS Configuration and Monitoring using Snort

Using Network Attached Storage with Linux. by Andy Pepperdine

Load Balancing/High Availability Configuration for neoninsight Server

CS10110 Introduction to personal computer equipment

Hadoop Hands-On Exercises

CTIS486 Midterm I 20/11/ Akgül

Setting up PostgreSQL

Downloading Files using FTP

Digital UNIX. Command and Shell User s Guide. Digital Equipment Corporation Maynard, Massachusetts

LAB THREE STATIC ROUTING

CLC Server Command Line Tools USER MANUAL

Transcription:

Outline CS4233 Network Programming Introduction to UNIX Chen-Lung Chan Department of Computer Science National Tsing Hua University UNIX Editors joe vi Shell script Variables Operators Logic structures Log In & Log Out System Information Log in login Log out logout exit date - print or set the system date and time cal - displays a calendar last - show listing of last logged in users df - report filesystem disk space usage which - shows the full path of (shell) whereis - locate the binary, source, and manual page files for a command

Screen & View Documents Screen control clear View file cat more less Redirect >, >> $ last > log.txt < $ last grep Tue man - format and display the on-line manual pages whatis - search the whatis database for complete words info - read Info documents Account passwd - update a user's authentication tokens finger - user information lookup program who - show who is logged on chfn - change your finger information chsh - change your login shell File Permissions - rw- type owner Case sensitive rw- group others The first character describes the file type d (directory) -(file) l (link) Other characters r (readable) w (writable) x (executable) r--

Directories Files Tree structure Commands cd pwd ls mkdir rmdir cp - copy files and directories rm - remove files or directories ln - make links between files chmod - change file access permissions chown - change file owner and group chgrp - change group ownership du - estimate file space usage touch - change file timestamps find - search for files in a directory hierarchy grep - print lines matching a pattern Process Network ps - report process status top - display top CPU processes kill - terminate a process & - run as a background process nice - run a program with modified scheduling priority ping - send ICMP ECHO_REQUEST packets to network hosts traceroute - print the route packets take to network host nslookup domain name look up netstat network connections, statistics mail - send and receive mail telnet - user interface to the TELNET protocol ftp - Internet file transfer program ncftp - browser program for the File Transfer Protocol

Wildcard Characters Outline? Match exactly one character Ex: $ ls /etc/f?stab * Match zero or more characters Ex: $ ls *.c [chars] Define a class of characters Ex: $ ls /etc/rc[1-3].d UNIX Editors joe vi Shell script Variables Operators Logic structures vi Modes Command mode Move the curser, enter other modes Initial mode Insert mode Data input Press i, a, or o in command mode Press ESC can back to command mode Last line mode Search string, exit, save Press :, /, or? in command mode Command Mode (1/2) Enter insert mode i (insert) a (append) o (new line) Move the curser h (left) j (down) k (up) l (right) Ctrl + f ( page down) Ctrl + b (page up)

Command Mode (2/2) Last Line Mode Move the curser cont d G (end of file) # + Enter (# of line) Delete x (delete a character) #x (delete # characters) dd (delete a line) #dd (delete # lines) : w (write) q (quit) e (edit) / Search from head to tail? Search from tail to head joe Outline Similar to edit in DOS. Commands Ctrl + KH (help) Ctrl + KX (save and exit) UNIX Editors joe vi Shell script Variables Operators Logic structures

Shells Bourne Shell (Bell LAB) Bourne Shell (sh) Bourne Again Shell (bash) Korne Shell (ksh) C shell (Berkley) C Shell (csh) Tenex C Shell (tcsh) Start Files sh /etc/profile $HOME/.profile bash $HOME/.bashrc csh /etc/csh.cshrc $HOME/.cshrc $HOME/.login tcsh $HOME/.tcshrc Environment Variables PATH $ PATH=/bin:/usr/bin:/usr/local/bin $ export PATH EDITOR $ EDITOR=/usr/bin/joe $ export EDITOR Shell Script Similar to *.bat in DOS Shell & shell script A text file contains several The shell interprets the text file and execute the Execution Pass the file as the parameter $ sh filename Make the file itself to be executable Insert #!/bin/sh in the first line $ chmod 755 [filename]

Format of Shell Script Composed by several lines Special characters \ Append the contents in the next line to current line # Add comments Similar to high-level languages Control statements Subprograms Programming Features Shell variables Keep values in memory Symbolic names that can access values stored in memory Use $ to get the value of a variable $SUM: the value of the variable SUM Operators Shell scripts support many operators Logic structures Sequential logic a series of Decision logic - branching Loop logic - repeating Case logic choosing an action from several possible alternatives Variables (1/3) Configuration variables Store information about the setup of the OS Do not change them Environment variables Will not be lost even the shell is changed Set a environment variable in bash [var]=[value] export [var] Variables (2/3) Shell variables Are only active in the current shell Set a shell variable in bash [var]=[value] Read-only user variables readonly [var] Type readonly to list all read-only variables Environment variables cannot be set as read-only

Variables (3/3) Operators (1/2) Special variables $0 name of current process $n the n th parameter, n=1..9 $* all parameters $# number of parameters $$ process ID Defining and evaluating operators = Set a value in a variable echo Display the contents of a variable $ echo $HOME /usr/xxxx/xxxxxxxx $ echo $HOME $HOME $ echo $HOME /user/xxxx/xxxxxxxx Operators (2/2) expr Defining and evaluating operators cont d `` Enclose UNIX whose output will become the contents of a variable $ MSG=`pwd` $ echo $MSG /xxxx/xxxx/xxxx Arithmetic operators expr Redirecting and piping operators >, <, Composed by strings and operands The results are output to the standard output Operations : compare two strings +, -, *, /, % <, <=, =,!=, >=, > & AND OR \ escape character length the length of the string Ex: $ expr 2 \* \( 3 + 4 \) 14

Examples Ex1: echo Hello world!! Ex2: str= Hello world!! echo $str Ex3: SUM=`expr 1 + 2 + 3` echo $SUM Logic Structures Sequential logic Execute Directly input ([command]) The same as the execution in command line Use shell to execute (sh [command]) The file must be a shell script Use exec (exec [command]) The new command will replace current shell Use ` to enclose [var]=`pwd` Store the output of [pwd] to [var] Decision Logic if statement if (condition) then then- fi if (condition) then then- else else- fi Looping Logic (1/2) for statement for [var] in [arg-list] do done for [var] do done

Looping Logic (2/2) while statement while (condition) do done until statement until (condition) do done Case Logic case [str] in pat1) 1;; pat2) 2;; pat3) 3;; esac Other Statements test (1/3) Input read Output echo Condition true false test break continue Formt test <expression> Logical operation -a AND -o OR! NOT Rules [str] the string [str] is not empty -n [str] the length of the string [str] is larger than 0 -z [str] the length of the string [str] equals to 0 [str1]=[str2] [str1] is the same as [str2] [str1]!=[str2] [str1] is different from [str2]

test (2/3) test (3/3) [int1] gt [int2] [int1] > [int2] [int1] ge [int2] [int1] >= [int2] [int1] eq [int2] [int1] = [int2] [int1] ne [int2] [int1]!= [int2] [int1] le [int2] [int1] <= [int2] [int1] lt [int2] [int1] < [int2] -r [filename] the file is readable -w [filename] the file is writable -x [filename] the file is executable -f [filename] the file is a general file -d [filename] the file is a directory -s [filename] the file is a nonempty general file compare.sh: if ( test 1 lt 2 ) then echo < else echo >= fi