PROGRAMMAZIONE I A.A. 2015/2016

Similar documents
Welcome to Linux. Lecture 1.1

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

CS246 Spring14 Programming Paradigm Notes on Linux

Introduction: What is Unix?

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

CENG 334 Computer Networks. Laboratory I Linux Tutorial

CSE 303 Lecture 4. users/groups; permissions; intro to shell scripting. read Linux Pocket Guide pp , 25-27, 61-65, , 176

GNU/Linux 101. Casey McLaughlin. Research Computing Center Spring Workshop Series 2018

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

Chapter 1 - Introduction. September 8, 2016

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

Introduction to Linux Workshop 1

EECS2301. Lab 1 Winter 2016

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

Files

Mills HPC Tutorial Series. Linux Basics I

Week 2 Lecture 3. Unix

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

Chapter 9. Shell and Kernel

Command-line interpreters

Scripting. Shell Scripts, I/O Redirection, Ownership and Permission Concepts, and Binary Numbers

Essential Linux Shell Commands

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

The Unix Shell & Shell Scripts

Lab 3a Using the vi editor

1. What statistic did the wc -l command show? (do man wc to get the answer) A. The number of bytes B. The number of lines C. The number of words

Operating Systems, Unix Files and Commands SEEM

Open up a terminal, make sure you are in your home directory, and run the command.

Exploring UNIX: Session 3

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

Introduction to UNIX I: Command Line 1 / 21

Introduction. Let s start with the first set of slides

CSE 15L Winter Midterm :) Review

commandname flags arguments

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

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

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

Unix basics exercise MBV-INFX410

Topic 2: More Shell Skills

Introduction to Unix: Fundamental Commands

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

24 Writing Your First Script

System Programming. Unix Shells

CSCI 2132 Software Development. Lecture 5: File Permissions

Introduction to Linux

Operating System Interaction via bash

Introduction to UNIX Command Line

Introduction to Linux

CISC 220 fall 2011, set 1: Linux basics

A Brief Introduction to the Linux Shell for Data Science

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

A shell can be used in one of two ways:

Basic Linux Command Line Interface Guide

Introduction to Supercomputing

Using bash. Administrative Shell Scripting COMP2101 Fall 2017

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

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

Introduction to Linux Basics

Unix Introduction to UNIX

UNIX System Programming Lecture 3: BASH Programming

I/O and Shell Scripting

Introduction to Linux for BlueBEAR. January

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

Lec 1 add-on: Linux Intro

Shell Scripting. Todd Kelley CST8207 Todd Kelley 1

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

Exercise Sheet 2. (Classifications of Operating Systems)

Linux & Shell Programming 2014

Course 144 Supplementary Materials. UNIX Fundamentals

Intro to Linux. this will open up a new terminal window for you is super convenient on the computers in the lab

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

Today. Review. Unix as an OS case study Intro to Shell Scripting. What is an Operating System? What are its goals? How do we evaluate it?

Chapter-3. Introduction to Unix: Fundamental Commands

CSCI 2132 Software Development. Lecture 4: Files and Directories

Std: XI CHAPTER-3 LINUX

RH033 Red Hat Linux Essentials

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

Basic Linux Command Line Interface Guide

B a s h s c r i p t i n g

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

Introduction to Linux

6.033 Computer System Engineering

Linux Systems Administration Shell Scripting Basics. Mike Jager Network Startup Resource Center

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

DAVE LIDDAMENT INTRODUCTION TO BASH

Introduction to Linux

Linux Systems Administration Getting Started with Linux

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

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

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

5/20/2007. Touring Essential Programs

Unix File System. Learning command-line navigation of the file system is essential for efficient system usage

Essentials for Scientific Computing: Bash Shell Scripting Day 3

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

Assignment clarifications

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.

Operating Systems. Copyleft 2005, Binnur Kurt

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

Prof. Navrati Saxena TA: R. Sachan

Basic UNIX commands. HORT Lab 2 Instructor: Kranthi Varala

Transcription:

PROGRAMMAZIONE I A.A. 2015/2016

SHELL

SHELL

SHELL A program that interprets commands Allows a user to execute commands by typing them manually at a terminal, or automatically in programs called shell scripts. A shell is not an operating system. It is a way to interface with the operating system and run commands.

BASH BASH = Bourne Again SHell Bash is a shell written as a free replacement to the standard Bourne Shell (/bin/sh) originally written by Steve Bourne for UNIX systems. It has all of the features of the original Bourne Shell, plus additions that make it easier to program with and use from the command line. Since it is Free Software, it has been adopted as the default shell on most Linux systems. MacBook-Francesco:~ francescosantini$ echo $SHELL /bin/bash MacBook-Francesco:~ francescosantini$

BASH AND DOS COMMAND PROMPT Case sensitivity: In Linux/UNIX, commands and filenames are case sensitive, meaning that typing EXIT instead of the proper exit is a mistake. Filenames: The DOS world uses the eight dot three filename convention, meaning that all files followed a format that allowed up to 8 characters in the filename, followed by a period ( dot ), followed by an option extension, up to 3 characters long (e.g. FILENAME.TXT). In UNIX/Linux, there is no such thing as a file extension. Periods can be placed at any part of the filename, and extensions may be interpreted differently by all programs, or not at all.

SPECIAL CHARACTERS

SPECIAL CHARACTERS

EXECUTING COMMANDS The Command PATH: Most common commands are located in your shell's PATH, meaning that you can just type the name of the program to execute it. üexample: Typing ls will execute the ls command. Your shell's PATH variable includes the most common program locations, such as /bin, /usr/bin, /usr/x11r6/bin, and others. To execute commands that are not in your current PATH, you have to give the complete location of the command. üexamples: /home/esercizi/esercizio1./esercizio1 (Execute a program in the current directory)

CHANGING PATH OF EXECUTABLES MacBook-Francesco:~ francescosantini$ echo $PATH /opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/ sbin:/opt/x11/bin:/usr/local/git/bin:/usr/texbin MacBook-Francesco:~ francescosantini$ PATH=$PATH:~/Desktop/ProgrammI/ MacBook-Francesco:~ francescosantini$ echo $PATH /opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin :/opt/x11/bin:/usr/local/git/bin:/usr/texbin:/users/francescosantini/de sktop/programmi/ You can run a program with a.out instead of./a.out

CHANGING PATH (PERMANENT) The command before does not work anymore if you close and restart the shell To make it permanent: ümodify the profile of your bash Edit file: ~/.bash_profile üadd :~/Desktop/ProgrammI/ at the end of the string

COMMAND SYNTAX Command Syntax: Commands can be run by themselves, or you can pass in additional arguments to make them do different things. Typical command syntax can look something like this: command [-argument] [--argument] [file] Examples: üls üls -l ücat filename ücat -n filename List files in current directory Lists files in long format Show contents of a file Show contents of a file, with line numbers MacBook-Francesco:~ francescosantini$ cat -n.bash_profile 1 PATH=$PATH:~/Desktop/ProgrammI/

HELP! Help on most Linux commands is typically 1) built right into the commands themselves, 2) available through online help programs ( man pages and info pages ). Using a Command's Built-In Help: Many commands have simple help screens that can be invoked with special command flags. These flags usually look like -h or --help. üexample: gcc --help

HELP! The best source of information for most commands can be found in the manual pages, known as man pages for short. To read a command's man page, type man command. Examples üman ls man man Get help on the ls command. A manual about how to use the manual! One you are in the manual, to search for a particular word within a man page, type /word. To quit from a man page, just type the Q key. Move up-down with arrows. Type h for help INSIDE man.

MAN FOR STDLIBRARY It works also for functions in standard library MacBook-Francesco:~ francescosantini$ man calloc

NAVIGATING THE LINUX FILESYSTEM

ROOT DIRECTORY The Linux filesystem is a tree-like hierarchy hierarchy of directories and files. At the base of the filesystem is the / directory, otherwise known as the root (not to be confused with the root user). Unlike DOS or Windows filesystems that have multiple roots, one for each disk drive, the Linux filesystem mounts all disks somewhere underneath the / filesystem.

MAIN DIRECTORIES

MAIN DIRECTORIES

COMMANDS FOR NAVIGATING

COMMANDS FOR NAVIGATING

.BASH_HISTORY less ~/.bash_history

PIPING AND REDIRECTION

PIPING The pipe character,, is used to chain two or more commands together. The output of the first command is piped into the next program, and if there is a second pipe, the output is sent to the third program, etc. For example: üls -la /usr/bin less In this example, we run the command ls -la /usr/bin, which gives us a long listing of all of the files in /usr/bin. Because the output of this command is typically very long, we pipe the output to a program called less, which displays the output for us one screen at a time.

REDIRECTING OUTPUT TO FILES There are times when it is useful to save the output of a command to a file, instead of displaying it to the screen. For example, if we want to create a file that lists all of the MP3 files in a directory, we can do something like this, using the > redirection character: üls -l /home/vic/mp3/*.mp3 > mp3files.txt A similar command can be written so that instead of creating a new file called mp3files.txt, we can append to the end of the original file: üls -l /home/vic/extramp3s/*.mp3 >> mp3files.txt

OTHER COMMANDS

OTHER COMMANDS

OTHER COMMANDS MacBook-Francesco:~ francescosantini$ rm *.o

FIND THINGS

INFORMATIONAL COMMANDS

MORE UTILITIES

GO FASTER

CHMOD ls -l The first character in this column tells what kind of file this is. The dash represents a normal file; the d represents a directory. The remaining characters describe the file s permissions The size of the file, in bytes. For directories, this is the size of the directory, not the total of the directory s contents!

PERMISSIONS - rwx r-x r-x joe acctg archive.sh - rw- rw- r-- joe acctg orgchart.gif - rw- rw- r-- joe acctg personnel.txt - rw- r-- r-- joe acctg publicity.html d rwx rwx r-x joe acctg sales - rw- r-- --- joe acctg topsecret.inf - rwx r-x r-x joe acctg wordomatic user group others

CHANGING PERMISSIONS Before: -rwx r-x r-x archive.sh Command: chmod o=r archive.sh After: -rw xr-x r-- archive.sh Before: -rw-r----- topsecret.inf Command: chmod g= topsecret.inf After: -rw- --- --- topsecret.inf u = user g = group o = others a = all r = read w = write x = execute Before: -rw- r-- r-- publicity.html Command: chmod og=rw publicity.html After: -rw- rw- rw- publicity.html

SHELL PROGRAMMING (INTRO)

EXAMPLE #!/bin/bash echo Hello World

INTRO You can put commands in a file and execute them in sequence. #!/bin/bash # Rotate procmail log files cd /homes/arensb/mail rm procmail.log.6 # This is redundant mv procmail.log.5 procmail.log.6 mv procmail.log.4 procmail.log.5 mv procmail.log.3 procmail.log.4 mv procmail.log.2 procmail.log.3 mv procmail.log.1 procmail.log.2 mv procmail.log.0 procmail.log.1 mv procmail.log procmail.log.0

THINGS TO NOTICE The first line of any script must begin with #!, followed by the name of the interpreter. Comments begin with a hash (#) and continue to the end of the line A script, like any file that can be run as a command, needs to be executable: save this script (text file) as rotatelog and run üchmod u=rwx rotatelog ü./ rotatelog