Part 1: Basic Commands/U3li3es

Similar documents
Useful Unix Commands Cheat Sheet

Shell Programming (ch 10)

Introduction p. 1 Who Should Read This Book? p. 1 What You Need to Know Before Reading This Book p. 2 How This Book Is Organized p.

Unix/Linux Basics. Cpt S 223, Fall 2007 Copyright: Washington State University

Shells and Shell Programming

Computer Systems and Architecture

Table of contents. Our goal. Notes. Notes. Notes. Summer June 29, Our goal is to see how we can use Unix as a tool for developing programs

Shells and Shell Programming

The UNIX Shells. Computer Center, CS, NCTU. How shell works. Unix shells. Fetch command Analyze Execute

CS197U: A Hands on Introduction to Unix

Linux Shell Script. J. K. Mandal

Computer Systems and Architecture

LOG ON TO LINUX AND LOG OFF

Perl and R Scripting for Biologists

3/8/2017. Unix/Linux Introduction. In this part, we introduce. What does an OS do? Examples

Shells. A shell is a command line interpreter that is the interface between the user and the OS. The shell:

CENG 334 Computer Networks. Laboratory I Linux Tutorial

ScazLab. Linux Scripting. Core Skills That Every Roboticist Must Have. Alex Litoiu Thursday, November 14, 13

Unix Guide. Meher Krishna Patel. Created on : Octorber, 2017 Last updated : December, More documents are freely available at PythonDSP

Basic Linux (Bash) Commands

Introduction to Linux Basics Part II. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

System Administration

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

Assignment clarifications

Bourne Shell (ch 8) Overview. Bourne Shell. Bourne Shell. Bourne Shell. Bourne Shell. Redirect standard error. Redirect standard error

Lab 2: Linux/Unix shell

Processes. Shell Commands. a Command Line Interface accepts typed (textual) inputs and provides textual outputs. Synonyms:

Introduction to remote command line Linux. Research Computing Team University of Birmingham

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

QUESTION BANK ON UNIX & SHELL PROGRAMMING-502 (CORE PAPER-2)

M2PGER FORTRAN programming. General introduction. Virginie DURAND and Jean VIRIEUX 10/13/2013 M2PGER - ALGORITHME SCIENTIFIQUE

Practical Session 0 Introduction to Linux

The Unix Shell. Pipes and Filters

Introduction To. Barry Grant

Windshield. Language Reference Manual. Columbia University COMS W4115 Programming Languages and Translators Spring Prof. Stephen A.

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 1

The Unix Shell & Shell Scripts

Topic 2: More Shell Skills

bash, part 3 Chris GauthierDickey

Unix Basics. Benjamin S. Skrainka University College London. July 17, 2010

BIOINFORMATICS POST-DIPLOMA PROGRAM SUBJECT OUTLINE Subject Title: OPERATING SYSTEMS AND PROJECT MANAGEMENT Subject Code: BIF713 Subject Description:

Chap2: Operating-System Structures

Introduction to Linux

Introduction to Linux

Linux Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

Recap From Last Time:

Linux environment. Graphical interface X-window + window manager. Text interface terminal + shell

INd_rasN SOME SHELL SCRIPTING PROGRAMS. 1. Write a shell script to check whether the name passed as first argument is the name of a file or directory.

Appendix B WORKSHOP. SYS-ED/ Computer Education Techniques, Inc.

BGGN 213 Working with UNIX Barry Grant

Topic 2: More Shell Skills. Sub-Topic 1: Quoting. Sub-Topic 2: Shell Variables. Difference Between Single & Double Quotes

Sub-Topic 1: Quoting. Topic 2: More Shell Skills. Sub-Topic 2: Shell Variables. Referring to Shell Variables: More

Scripting Languages Course 1. Diana Trandabăț

Introduction to UNIX. Logging in. Basic System Architecture 10/7/10. most systems have graphical login on Linux machines

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 2

Command-line interpreters

Linux Essentials Objectives Topics:

Introduction to Linux

Introduction to UNIX. Introduction. Processes. ps command. The File System. Directory Structure. UNIX is an operating system (OS).

Introduction to UNIX. CSE 2031 Fall November 5, 2012

Linux Command Line Interface. December 27, 2017

Introduction to the Linux Command Line January Presentation Topics

Shell Programming Systems Skills in C and Unix

Introduction of Linux

Introduction Into Linux Lecture 1 Johannes Werner WS 2017

Introduction to UNIX Command Line

INSE Lab 1 Introduction to UNIX Fall 2017

SANJAY GHODAWAT POLYTECHNIC

d. Permissions 600 on directory dir and 300 on file dir/foo. c. Permissions 700 on directory dir and 200 on file dir/foo.

Introduction To. Barry Grant

CISC 220 fall 2011, set 1: Linux basics

5/8/2012. Creating and Changing Directories Chapter 7

CSE 390a Lecture 2. Exploring Shell Commands, Streams, Redirection, and Processes

unix intro Documentation

UNIX Shell Programming

Linux shell programming for Raspberry Pi Users - 2

Introduction to UNIX. Introduction EECS l UNIX is an operating system (OS). l Our goals:

COMS 6100 Class Notes 3

More Raspian. An editor Configuration files Shell scripts Shell variables System admin

Shells & Shell Programming (Part B)

CS 25200: Systems Programming. Lecture 11: *nix Commands and Shell Internals

CSCI 211 UNIX Lab. Shell Programming. Dr. Jiang Li. Jiang Li, Ph.D. Department of Computer Science

CSE Linux VM. For Microsoft Windows. Based on opensuse Leap 42.2

Command Line Interface Techniques

Basic UNIX Commands BASIC UNIX COMMANDS. 1. cat command. This command is used to create a file in unix. Syntax: $ cat filename

Mid Term from Feb-2005 to Nov 2012 CS604- Operating System

UNIX Essentials Featuring Solaris 10 Op System

Introduction to Unix The Windows User perspective. Wes Frisby Kyle Horne Todd Johansen

Set 1 MCQ Which command is used to sort the lines of data in a file in reverse order A) sort B) sh C) st D) sort -r

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

CS370 Operating Systems

Linux Shell Scripting. Linux System Administration COMP2018 Summer 2017

Lecture 3. Unix. Question? b. The world s best restaurant. c. Being in the top three happiest countries in the world.

File permission u owner of file/directory (user) g group of the file/directory o other a all

DAVE LIDDAMENT INTRODUCTION TO BASH

Command Interpreters. command-line (e.g. Unix shell) On Unix/Linux, bash has become defacto standard shell.

CSE 303 Lecture 2. Introduction to bash shell. read Linux Pocket Guide pp , 58-59, 60, 65-70, 71-72, 77-80

Exercise 1: Basic Tools

Open Source Computational Fluid Dynamics

Unix Processes. What is a Process?

Transcription:

Final Exam Part 1: Basic Commands/U3li3es May 17 th 3:00~4:00pm S-3-143 Same types of questions as in mid-term 1 2 ls, cat, echo ls -l e.g., regular file or directory, permissions, file size ls -a cat file1 file2 file3 echo hello world > file echo $VAR, echo hello* echo n hello world more, less, head, tail head -5 file tail -f file pwd, cd cp, mv, rm, mkdir, rmdir -i option -r option: rm r dir1, cp r dir1 dir2 rmdir an empty directory 3 4 sort, wc, grep, (pipe) wc -l file, wc c file grep keyword file grep -v sort linux head -5 command1 command2 command1 > temp command2 < temp rm temp Part 2: File Systems 5 6 1

Filename and Path Hierarchical tree structure Absolute path name ls /home/it244/it244 Relative path name cd /home/it244 ls it244... ~ *? echo hello*, echo./.?a* Access Permissions r, w, x (chmod) chmod a+rw file chmod a=rx file chmod 644 file Execute permission of a directory A directory is a table of files (filename:meta) Executable means searchable 7 8 Access Permissions Operations on book/book1 ls book/book1 book ( x ) cat book/book1 book1 ( r ), book ( x ) rm book/book1 book ( xw ), book1 ( w ) Links Hard link and soft link Hard link cannot refer to a directory Soft link can point to a nonexistent file $ ln -s hello hello.sl $ rm hello $ echo new > hello $ cat hello.sl new 9 10 Execute Commands Part 3: Bash/Shell Scrip3ng Foreground and background jobs command &, CTRL+Z difference between a suspended job and a background job, PID jobs, ps, kill, bg, fg Group commands (cmd1; cmd2; cmd3) 11 12 2

Redirection Standard input, output, error output cat file1 file2 > out 2>err cat file1 file2 &> out cat file1 file2 > out 2>&1 Redirected output will not be displayed on the screen. System variables $PATH, $PWD, $HOME User defined variables VAR=hello export VAR=hello declare; declare -x 13 14 New shell for executing a script $cat script1 echo $VAR VAR=new echo $VAR $VAR=old;./script1;echo $VAR $VAR=new./script1;echo $VAR Expansion/ Quote Types echo hello*; echo ~ echo $VAR echo $(pwd) echo $((1+1)) VAR=hello* echo $VAR $export VAR=old;./script1;echo $VAR Single quote suspends all expansions 15 16 if..then..fi, if..then..else..fi, while test-command commands for loop-index in argument-list commands Conditions test $# -eq 0 [ -f $1 ] [ condition1 a condition2 ], -o [[ && ]], (( )) Exit status $? if [ read <file $line ] 17 18 3

cond1 cond2 cond1 && cond2 cond1 cond2 True True True True True False False True False True False True False False False false Short circuiting $((a=2, b=2)) $((a++ b--)) $echo $a $b $((--a>2 b++)) $echo $a $b 19 20 Short circuiting (($#==2)) echo "Usage:require two arguments mkdir $1 && cp file1 $1 Arguments $1-$n, $0, $#, $@ set set a 123 hello echo $1 $2 $3 set $(date) shift echo $@ shift echo $@ $$, $? 21 22 File I/O exec exec 3 < infile exec 4 > outfile read read -p Enter sth: input1 input2 read <&3 line, read u3 line Determine the end of a file $line has no value read returns false Write to a file echo abc >&4 Part 4: Perl/AWK/SED 23 24 4

Run a Program Patterns Perl perl simple.pl perl e print hi\n AWK gawk -f simple file gawk /chevy/ {print} file SED sed -f simple file sed /line/ p file Stand-alone scripts #!/usr/bin/perl #!/usr/bin/gawk -f #!/bin/sed -f AWK awk /chevy/ {print} cars gawk $1 ~ /h/ cars gawk $5 > 2000 && $5<6000 cars SED sed -n 3,6 p lines sed n s/line/sentence/w temp lines 25 26 File I/O in perl Read open ($infile, '<', filename ); while ($line=<$infile>){ print $line; } $line=<> If we execute the following sequence of commands in order, what are the values of variables a, b and the output AFTER executing each line? $((a=1, b=2)) $echo $((a-- + b++)) a=_0_, b=_3_, output=_3_ $echo $((a++ + ++b)) a=_1_, b=_4_, output=_4_ Write $filename="./log"; open($outfile,'>',$filename); print $outfile "Hello world!\n"; 27 28 Read the following shell script and explain its function. Read the following shell script and answer the questions $ cat script1 #!/bin/bash count=0 for i in * then ((count++)) fi echo $count $cat script1 #!/bin/bash exec 3<$1 exec 4<$2 exec 5>$3 while read line <&3 echo $line >&5 while read line <&4 echo $line >&5 Q1. The script requires 3 filenames as arguments, e.g.,./script1 file1 file2 file3 Which files are input files and which are output files? Q2. Inside the while-loop, why variable $line has to be enclosed by uble quotes? 29 30 5