Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Mauro Ceccanti e Alberto Paoluzzi

Similar documents
Lezione 8. Shell command language Introduction. Sommario. Bioinformatica. Esercitazione Introduzione al linguaggio di shell

CS246 Spring14 Programming Paradigm Notes on Linux

EECS2301. Lab 1 Winter 2016

Introduction: What is Unix?

CISC 220 fall 2011, set 1: Linux basics

5/20/2007. Touring Essential Programs

Introduction to the Linux Command Line

EE516: Embedded Software Project 1. Setting Up Environment for Projects

UNIX COMMANDS AND SHELLS. UNIX Programming 2015 Fall by Euiseong Seo

Introduction to Linux. Fundamentals of Computer Science

CS CS Tutorial 2 2 Winter 2018

Unix Handouts. Shantanu N Kulkarni

Linux & Shell Programming 2014

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

Introduction to Cygwin Operating Environment

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

Common UNIX Commands. Unix. User Interfaces. Unix Commands Winter COMP 1270 Computer Usage II 9-1. Using UNIX. Unix has a command line interface

Unix Shells and Other Basic Concepts

Linux Operating System Environment Computadors Grau en Ciència i Enginyeria de Dades Q2

The Unix Shell & Shell Scripts

Linux at the Command Line Don Johnson of BU IS&T

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

Introduction to Unix: Fundamental Commands

System Administration

Contents. Note: pay attention to where you are. Note: Plaintext version. Note: pay attention to where you are... 1 Note: Plaintext version...

Perl and R Scripting for Biologists

Operating Systems. Copyleft 2005, Binnur Kurt

Operating Systems 3. Operating Systems. Content. What is an Operating System? What is an Operating System? Resource Abstraction and Sharing

Linux Training. for New Users of Cluster. Georgia Advanced Computing Resource Center University of Georgia Suchitra Pakala

Linux Systems Administration Getting Started with Linux

Mills HPC Tutorial Series. Linux Basics I

Introduction to Linux. Woo-Yeong Jeong Computer Systems Laboratory Sungkyunkwan University

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

Chapter-3. Introduction to Unix: Fundamental Commands

CENG 334 Computer Networks. Laboratory I Linux Tutorial

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

Getting started with Hugs on Linux

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

Introduction of Linux

Session 1: Accessing MUGrid and Command Line Basics

Introduction to Linux Part 1. Anita Orendt and Wim Cardoen Center for High Performance Computing 24 May 2017

Crash Course in Unix. For more info check out the Unix man pages -orhttp:// -or- Unix in a Nutshell (an O Reilly book).

CSCI 2132 Software Development. Lecture 3: Unix Shells and Other Basic Concepts

Introduction to Linux

Week 2 Lecture 3. Unix

Introduction to Shell Scripting

Unix System Architecture, File System, and Shell Commands

Introduction to Linux Basics

CHE3935. Lecture 1. Introduction to Linux

UNIX. The Very 10 Short Howto for beginners. Soon-Hyung Yook. March 27, Soon-Hyung Yook UNIX March 27, / 29

Introduction to Linux

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

Introduction to Linux

Practical Computing-II. Programming in the Linux Environment. 0. An Introduction. B.W.Gore. March 20, 2015

Introduction to Linux (Part I) BUPT/QMUL 2018/03/14

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

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Unix basics exercise MBV-INFX410

CS Fundamentals of Programming II Fall Very Basic UNIX

Unix L555. Dept. of Linguistics, Indiana University Fall Unix. Unix. Directories. Files. Useful Commands. Permissions. tar.

Introduction to the Shell

UNIX File Hierarchy: Structure and Commands

Introduction to Unix and Linux. Workshop 1: Directories and Files

INF322 Operating Systems

CS 307: UNIX PROGRAMMING ENVIRONMENT KATAS FOR EXAM 1

Getting started with Hugs on Linux

Outline. Structure of a UNIX command

Getting Started with UNIX

Introduction to Linux

Introduction to Linux

Introduction to Linux

Introduction to the UNIX command line

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

Unix Workshop Aug 2014

Introduction to UNIX Command Line

Introduction to UNIX I: Command Line 1 / 21

Using LINUX a BCMB/CHEM 8190 Tutorial Updated (1/17/12)

Vi & Shell Scripting

Unix File System. Class Meeting 2. * Notes adapted by Joy Mukherjee from previous work by other members of the CS faculty at Virginia Tech

Unix as a Platform Exercises. Course Code: OS-01-UNXPLAT

ACS Unix (Winter Term, ) Page 21

Assignment clarifications

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

commandname flags arguments

(a) About Unix. History

CS 300. Data Structures

Welcome to Linux. Lecture 1.1

LING 408/508: Computational Techniques for Linguists. Lecture 5

I/O and Shell Scripting

Introduction to Linux Workshop 1

Unix Basics. Systems Programming Concepts

PROGRAMMAZIONE I A.A. 2015/2016

Brief Linux Presentation. July 10th, 2006 Elan Borenstein

Chapter 4. Unix Tutorial. Unix Shell

A Big Step. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Introduction to Linux

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

Std: XI CHAPTER-3 LINUX

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.

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

Transcription:

Lezione 8 Bioinformatica Mauro Ceccanti e Alberto Paoluzzi Dip. Informatica e Automazione Università Roma Tre Dip. Medicina Clinica Università La Sapienza Sommario Shell command language Introduction A Unix shell is a command-line interpreter (see shell) and script host that provides a traditional user interface for the Unix operating system and for Unix-like systems. The most generic sense of the term shell means any program that users employ to type commands. In the Unix operating system users may select which shell to use for interactive sessions. Many shells created for other operating systems (e.g. DOS for Windows) offer rough equivalents to Unix shell functionality.

Shell command languages Unix shells can be broadly divided into Bourne-like and C shell-like Bourne shell compatible sh Bourne shell Written by Steve Bourne, while at Bell Labs. First distributed with Version 7 Unix, circa 1978, bash Bourne-Again shell Written as part of the GNU project to provide a superset of Bourne Shell functionality. zsh Z shell considered as the most complete shell: it is the closest thing that exists to a superset of sh, ash, bash, csh, ksh, and tcsh. C shell compatible csh C shell Written by Bill Joy, while at the University of California, Berkeley. First distributed with BSD, circa 1979. tcsh Tenex shell It is essentially the C shell with programmable command line completion and command-line editing. Unix shells are Bourne-like or C shell-like a typical prompt to the user is structured as <host>:<path> <account>$, where the char tilde ( ) stands for the user s home directory: 1 baruc3:~ paoluzzi$ The Bourne shell is immediately recognized when active by its characteristic default command line prompt character, the dollar sign ($). The default for new Mac OS X accounts is bash. 1 <prompt>$ echo $SHELL 2 /bin/bash A command is followed by the shell s answer on the following row. No answer just means that the command was executed with no errors. Conversely, the shell complains quite strongly for errors. Introduction to shell command language First Unix commands 1 <prompt>$ ls 2 Desktop Movies Sites lib 3 Documents Music System libexec 4 Downloads Pictures bin scipy 5 Library Public ebooks share 6 <prompt>$ pwd 7 /Users/paoluzzi 8 <prompt>$ ls Users 9 <prompt>$ ls /Users 10 Shared paoluzzi 11 <prompt>$ ls / 12 Applications Volumes net 13......... 14 <prompt>$ cd / 15... 1 ls is a command to list files in Unix and Unix-like operating systems 6 pwd short for print working directory 9 ls /Users absolute path of a directory 14 cd / stands for change directory to root (directory) Shell Variables and Environment Variables These variables cause the shell to work in a particular way 1 <prompt>$ cd Users/ 2 -bash: cd: Users/: No such file or directory 3 <prompt>$ ls 4 Desktop Movies Sites lib 5 Documents Music System libexec 6 Downloads Pictures bin scipy 7 Library Public ebooks share 8 <prompt>$ echo $PATH 9 /opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/ sbin:/usr/local/bin:/usr/x11/bin:/usr/local/bin:/ Users/paoluzzi/bin 10 <prompt>$ cd. 11 <prompt>$ cd.. 12 <prompt>$ pwd 13 /Users 8 echo shows the contents ($) of the shell variable PATH searched for executing programs (including shell commands). Paths are separated by colon : punctuation mark

Change directory 1 <prompt>$ cd.. 2 <prompt>$ cd Volumes/ 3 <prompt>$ ls 4 Macintosh HD 5 <prompt>$ ls /bin/ls 6 /bin/ls* 7 <prompt>$ ls /bin/ 8 [ df launchctl pwd tcsh bash domainname link rcp test 9 cat echo ln rm unlink chmod ed ls rmdir wait4path 10 cp expr mkdir sh zsh csh hostname mv sleep 11 date kill pax stty dd ksh ps sync 12 <prompt>$ cd 13 <prompt>$ ls 14 Desktop Movies Sites ebooks share 15......... 1 cd to.. (parent directory) 5 no results for 6 OK 11 cd without parameters changes the directory to the user s home Output redirection and text editing 1 <prompt>$ echo "ciao" 2 ciao 3 <prompt>$ echo "ciao" > hello.txt 4 <prompt>$ ls 5 <prompt>$ cat hello.txt 6 ciao 7 <prompt>$ vi hello.txt 8 <prompt>$ emacs hello.txt 9 <prompt>$ nano hello.txt 1 echo of the string at console 3 output of echo command redirected to the hello.txt file 5 cat (concatenate) the contents hello.txt file on the console 7 editor vi opens the hello.txt file (:q<enter> to quit) 8 editor emacs opens hello.txt (<cntl>x<cntl>c to close) 9 editor nano opens hello.txt (uses menus: stands for <cntl>) Nano screen editing Useful commend menus. Easy to use Copy command 1 <prompt>$ cp hello.txt hello2.txt 2 <prompt>$ cp hello.txt hello3.txt 3 <prompt>$ cp hello.txt hello4.txt 4 <prompt>$ cp hello.txt hello5.txt 5 <prompt>$ ls 6 Desktop Music bin hello3.txt scipy 7 Documents Pictures cd hello4.txt share 8 Downloads Public ebooks hello5.txt 9 Library Sites hello.txt lib 10 Movies System hello2.txt libexec 11 <prompt>$ cat hello.txt hello2.txt hello3.txt 12 ciao 13 ciao 14 ciao 1 copy <input file name> <output file name> 5 the working directory now contains the new files 11 cat concatenates several input files

Move command the mv command just changes the file name. It is used to rename files and directories 1 <prompt>$ mv hello2.txt hello21.txt 2 <prompt>$ mv hello3.txt hello31.txt 3 <prompt>$ mv hello4.txt hello41.txt 4 <prompt>$ mv hello5.txt hello51.txt 5 <prompt>$ ls 6 Desktop Music bin hello31.txt scipy 7 Documents Pictures cd hello41.txt share 8 Downloads Public ebooks hello51.txt 9 Library Sites hello.txt lib 10 Movies System hello21.txt libexec 11 <prompt>$ cat hello.txt hello21.txt hello31.txt 12 ciao 13 ciao 14 ciao 1 move <input file name> <output file name> Iteration using the for cycle, the ; command terminator, and a shell variable i 1 A number of characters are interpreted by the Unix shell before any other action takes place. These characters are known as wildcard characters. Usually these characters are used in place of filenames or directory names. 1 <prompt>$ for i in *.txt; do ls $i; done 2 hello.txt 3 hello2.txt 4 hello3.txt 5 hello4.txt 6 hello5.txt 7 <prompt>$ ls -l hello* 8 --w-r--r-- 1 paoluzzi staff 5 Nov 9 19:14 hello.txt 9 -rw-r--r-- 1 paoluzzi staff 5 Nov 9 19:17 hello21.txt 10 -rw-r--r-- 1 paoluzzi staff 5 Nov 9 19:17 hello31.txt 11 -rw-r--r-- 1 paoluzzi staff 5 Nov 9 19:17 hello41.txt 12 -rw-r--r-- 1 paoluzzi staff 5 Nov 9 19:17 hello51.txt 1 Notice the different use of i and $i. 7 An asterisk matches any number of characters in a filename, including none. Permissions and chmod chmod is short for change mode. When executed, it can change file system modes of files and directories: $ chmod <references><operator><modes> file1... Executable script The first line (bang command #!) tells the shell where to find the program to interpret the file 1 <prompt>$ chmod u-r hello.txt 2 <prompt>$ ls -l hello.txt 3 --w-r--r-- 1 paoluzzi staff 5 Nov 9 19:14 hello.txt 4 <prompt>$ chmod u+r hello.txt 5 <prompt>$ ls -l hello.txt 6 -rw-r--r-- 1 paoluzzi staff 5 Nov 9 19:14 hello.txt 7 <prompt>$ cat hello.txt 8 cat: hello.txt: Permission denied 9 <prompt>$ chmod a-r hello.txt 10 <prompt>$ ls -l hello.txt 11 --w------- 1 paoluzzi staff 5 Nov 9 19:14 hello.txt 12 <prompt>$ chmod a+r hello.txt 13 -rw-r--r-- 1 paoluzzi staff 5 Nov 9 19:14 hello.txt references u (user) g (group) o (others) a (all) operator + (add) - (remove) = (no change) modes r (read) w (write) x (execute)

Executing the script assign execution permission & correct the path of the sh command in a.sh file 1 $ nano a.sh 2 $ ls -l a.sh 3 -rw-r--r-- 1 paoluzzi staff 50 Nov 10 09:43 a.sh 4 $ a.sh 5 -bash: a.sh: command not found 6 $ pwd 7 /Users/paoluzzi 8 $ /Users/paoluzzi/a.sh 9 -bash: /Users/paoluzzi/a.sh: Permission denied 10 $ chmod a+x a.sh 11 $ ls -l a.sh 12 -rwxr-xr-x 1 paoluzzi staff 50 Nov 10 09:43 a.sh 13 $ /Users/paoluzzi/a.sh 14 -bash: /Users/paoluzzi/a.sh: /usr/bin/sh: bad interpreter: No such file or directory 15 $./a.sh 16 -bash:./a.sh: /usr/bin/sh: bad interpreter: No such file or directory 17 $ which sh 18 /bin/sh Executable script correct the path of the sh program and save the file Executing the script assign execution permission & correct the path of the sh command in a.sh file Executing the script REMARK: launch the script with a path 1 $ a.sh 2 $./a.sh 3 ciao 4 ciao 5 ciao 6 ciao 7 ciao 1 no effect, even if the file exists in the current directory, and is provided with permission for execution. 2 it executes if launched from the current directory, because now the shell knows where to find it Executable programs are searched in the directories listed in the $PATH variable. The current directory (.) and its father (..) are not included by default for security reasons.

Executing on a remote machine Using a secure shell command ssh 1 baruc3:~ paoluzzi$ ssh paoluzzi@plm.dia.uniroma3.it 2 Password: 3 4 Last login: Fri May 22 12:29:46 2009 from authentication.uniroma3.it 5 6 paoluzzi@plm:~$ 7 paoluzzi@plm:~$ ls 8 Desktop/ Music/ download/ local/ tower-last/ 9...... 10 paoluzzi@plm:~$ exit 11 logout 12 Connection to plm.dia.uniroma3.it closed by remote host. 13 Connection to plm.dia.uniroma3.it closed. Fundamental programming in the Bourne again shell (bash) for a professional introduction to bash shell programming, see: Bash by example, Part 1 Bash by example, Part 2 Bash by example, Part 3 1 <prompt>$ ssh <account>@<remotehost> 2 Of course you need an account on the remote host 6 Notice the change in the user prompt