Welcome to Linux. Lecture 1.1

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

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

UNIX Concepts COMPSCI 386

CS246 Spring14 Programming Paradigm Notes on Linux

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

Introduction to Linux

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

CSC209. Software Tools and Systems Programming.

EECS2301. Lab 1 Winter 2016

An Introduction to Unix Power Tools

PROGRAMMAZIONE I A.A. 2015/2016

EECS 470 Lab 5. Linux Shell Scripting. Friday, 1 st February, 2018

Linux & Shell Programming 2014

Unix Handouts. Shantanu N Kulkarni

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

CISC 220 fall 2011, set 1: Linux basics

Introduction to Linux Basics

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

5/20/2007. Touring Essential Programs

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

UNIX File Hierarchy: Structure and Commands

Introduction to Linux

Introduction to Linux

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

CSC209. Software Tools and Systems Programming.

Introduction to Unix: Fundamental Commands

Unix Introduction to UNIX

Overview of Unix / Linux operating systems

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

UNIX Kernel. UNIX History

Introduction to Linux

Perl and R Scripting for Biologists

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

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

12/7/10 ATSC 212 UNIX ATSC 212 ATSC 212 UNIX

Filesystem and common commands

Overview LEARN. History of Linux Linux Architecture Linux File System Linux Access Linux Commands File Permission Editors Conclusion and Questions

Introduction: What is Unix?

Operating Systems, Unix Files and Commands SEEM

Scripting Languages Course 1. Diana Trandabăț

Working with Basic Linux. Daniel Balagué

Introduction. Let s start with the first set of slides

Linux for Beginners. Windows users should download putty or bitvise:

Unix System Architecture, File System, and Shell Commands

A Brief Introduction to Unix

Computer Systems and Architecture

Hitchhiker s Guide to VLSI Design with Cadence & Synopsys

commandname flags arguments

INTRODUCTION TO LINUX

CS 300. Data Structures

CSCI2467: Systems Programming Concepts

The Unix Shell & Shell Scripts

Introduction of Linux

AOS Linux Tutorial. Introduction to Linux. Michael Havas Dept. of Atmospheric and Oceanic Sciences McGill University. September 15, 2011

Classic Systems: Unix and THE. Presented by Hakim Weatherspoon

The UNIX File System

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

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

Chapter-3. Introduction to Unix: Fundamental Commands

CSN08101 Digital Forensics. Module Leader: Dr Gordon Russell Lecturers: Robert Ludwiniak

Brief Linux Presentation. July 10th, 2006 Elan Borenstein

Unix/Linux: History and Philosophy

Introduction to Cygwin Operating Environment

Assignment clarifications

Introduction to Linux

I/O and Shell Scripting

Operating System Labs. Yuanbin Wu

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

Read the relevant material in Sobell! If you want to follow along with the examples that follow, and you do, open a Linux terminal.

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

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

Introduction to Linux

Lecture Topics. Announcements. Today: Operating System Overview (Stallings, chapter , ) Next: Processes (Stallings, chapter

System Programming. Introduction to Unix

Introduction to the UNIX command line

Unix Internal Assessment-2 solution. Ans:There are two ways of starting a job in the background with the shell s & operator and the nohup command.

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

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

PESIT Bangalore South Campus

Chapter 1 - Introduction. September 8, 2016

Introduction to the Linux Command Line January Presentation Topics

Permission and Ownership

Computer Systems and Architecture

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

CENG 334 Computer Networks. Laboratory I Linux Tutorial

Chap2: Operating-System Structures

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

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.

Files and Directories

Week 2 Lecture 3. Unix

The UNIX File System

CST8207: GNU/Linux Operating Systems I Lab Six Linux File System Permissions. Linux File System Permissions (modes) - Part 1

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

Unix Basics. Systems Programming Concepts

Introduction to Linux. Roman Cheplyaka

Command-line interpreters

d. 1 e. test: $a: integer expression expected

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Transcription:

Welcome to Linux Lecture 1.1

Some history 1969 - the Unix operating system by Ken Thompson and Dennis Ritchie Unix became widely adopted by academics and businesses 1977 - the Berkeley Software Distribution (BSD) by UC Berkeley. A lawsuit USL v. BSDi. 1983 the GNU project by Richard Stallman - a free UNIX-like operating system (GPL). GNU incomplete no kernel 1991- Linus Torvalds, an undergraduate student from Finland, began a just for fun project that later became the Linux kernel.

Linux operating system Open-source Written in portable yet highly efficient language Built-in networking Built-in multitasking Rich software development environment Open interface to kernel Powerful and flexible CLI (command-line interface)

UNIX is very simple, it just needs a genius to understand its simplicity Dennis Ritchie, creator of C programming language

Scope for the first 2 weeks Get familiar with Linux Use existing utilities with CLI Shell programming

Scope for the rest of the course Develop our own utilities (tools) in a Unix-style Write application programs which interact with Linux kernel All this using C programming language

Linux structure Tools: We are interested in these

Linux kernel Process creation, and scheduling multiple processes Memory management: allocation, release File system on disk: abstraction over physical disk blocks Access to I/O devices: device drivers Networking: routing and exchange of messages Interface for user programs to perform requests to kernel: system calls

Linux file system ls -li

File abstraction Everything is a file. Unified file interface = open, read, write, close for regular files directories devices video keyboard network

Index node - inode The data for each file is managed by an array of on-disk data structures called inodes One inode is allocated for each file and each directory Unix inodes have unique numbers, not names, and it is these numbers that are kept in directories alongside the names. ls -i

Typical Linux file hierarchy Everything starts in the root directory A directory is a file that contains directory entries: pairs of (child name, inode). ================ ========================== R O O T <[etc,bin,home] >-- ROOT directory has no name! / \ / \ etc bin home [passwd] [ls,rm] [user1] / \ \ / \ ls rm user1 <data> <data> [.bashrc] passwd.bashrc <data> <data>

What is stored in inodes - example i directory What is stored 8 top [world-9, ] 9 world [lang-10, food-11] 10 lang [ENG-12, FRA-16, RUS-17] 11 food [CHN-13, ITA-18] 12 ENG [letter1-14] 13 CHN [noodles-15] 14 letter1 File data blocks 15 noodles File data blocks lang ENG FRA RUS letter1 (Top) world food CHN ITA noodles

File vs. directory inodes File inode location of data Directory inode location of (name, inode) pairs for child directories You must use the inode number from the directory to find the inode on disk to read its attribute information; reading the directory only tells you the name and inode number.

What is NOT stored in inodes? i directory What is stored 8 top [world-9, ] 9 world [lang-10, food-11] 10 lang [ENG-12, FRA-16, RUS-17] 11 food [CHN-13, ITA-18] 12 ENG [letter1-14] 13 CHN [noodles-15] 14 letter1 File data blocks 15 noodles File data blocks lang ENG FRA RUS letter1 (Top) world food CHN ITA noodles The name of a file is NOT stored in file inode it is stored in the parent directory

Noname files The name and inode number pair in a directory is the only connection between a name and the thing it names on disk If a directory is damaged, the names of the things are lost and inodes become orphan The things themselves may be undamaged. You can run a file system recovery program such as fsck to recover the data (but not the names)

What else is stored in inodes In addition to a list of pointers to the disk blocks: The attributes of the file or directory itself (permissions, size, access/modify times, etc.); but, not the name of the file or directory: The names are kept separately, in parent directories Directory inode stores two additional (name, inode) pairs: Itself:. inode Parent:.. inode

Multiple names to the same file: hard links An entry in a directory file which specifies a pair of (name, inode) is called a hard link. There can be several hard links to the same physical file! ln bar foo ls -li

Hard link example i directory What is stored 11 food [CHN-13, ITA-18] 12 ENG [letter1-14] 13 CHN [noodles-15] 14 letter1 File data blocks 15 noodles File data blocks 16 17 18 ITA [pasta-15] lang ENG FRA RUS letter1 (Top) world food CHN ITA noodles pasta cd world/food ln CHN/noodles ITA/pasta 2 names of the same file

Tracing inodes example: /home/alex/foobar From: http://teaching.idallen.com/cst8207/13w/notes/450_file_system.html

Directories cannot have hard links! Files may have many names ("links") - but directories can not! Each directory inode is allowed to appear once in exactly one parent directory and no more. Every sub-directory only has one parent directory, and the special name ".." (dot dot) always refers unambiguously to its unique parent directory This directory linking restriction prevents loops and cycles in the file system tree

ln vs. ln s Storage Space: no new inodes with hard links - in soft links we create a new inode to store the path to the file Performance: directly accessing the disk pointer instead of going through the path stored in soft link file. Renaming (mv) target file: the hard link will still work, but soft link will point to the previous file location. Redundancy: with hard link, the data is safe, until all the links to the file are deleted - in soft link, you will lose the data if the master instance of the file is deleted.

Programmable shell Running built-in utilities

Shells Special-purpose programs designed to read commands typed by the user and shell scripts, interpret them, and execute appropriate programs in response Many shells, i.e.: Bourne shell (SH) Bourne again shell (BASH) We are using this

How the shell is collaborating with the kernel Shell: accepts command names and arguments as input finds the executable interprets the arguments loads an executable into memory and hands it off to the OS to run. Kernel: starts the process of executing the program

How does shell know where to find an executable PATH variable: List of directories to be consulted when looking up commands specified without path names. E.g. you type "cat", it execs "/bin/cat". It finds it by looking through the path, which is a list of directories including /bin. echo "$PATH" /bin:/usr/bin:. PATH=$PATH:/path/to/dir1; export PATH To add permanently: Current directory echo 'export PATH=$PATH:/usr/local/bin' >> ~/.bash_profile

Globbing Globbing - process of expanding a non-specific file name containing a wildcard character into a set of specific file names that exist Standard wildcards (globbing patterns) * matches any number of any character? matches any one character [range] : m[a,o,u]m, m[a-d]m {} matches at least one (or): cp {*.doc,*.pdf} ~ [!] excluding rm myfile[!9]

Sharing files: permissions

Users belong to user groups (up to 16-32 groups max) wolf:~% groups mgbarsky mgbarsky : instrs csc209h csc343h csc443h cs209hi cs343hi cs443hi

Permissions as numbers Number Octal Representation Ref 0 No permission --- 1 Execute permission --x 2 Write permission -w- 3 Execute and write permission: 1 (execute) + 2 (write) = 3 -wx 4 Read permission r-- 5 Read and execute permission: 4 (read) + 1 (execute) = 5 r-x 6 Read and write permission: 4 (read) + 2 (write) rw- = 6 7 All permissions: 4 (read) + 2 (write) + 1 (execute) = 7 rwx

chmod -rwxr-xr-x Setting permissions chmod 755 <filename> 3 numbers between 0 and 7, the octal value for that category of user Quiz what is the command to set the permissions of the file classlist to be world readable but writeable only by the file owner and members of the group. Or using: chmod u+rwx chmod go-x chmode a=x adds or removes permissions for those categories of users

File Permissions chmod (change mode) Changes the permissions (mode) on an existing inode (file, directory, etc.) ls -lid (list structure, long version, inode, directory) Shows the permissions of an inode

Output redirection If the notation > file is appended to any command that normally writes its output to standard output, the output of that command will be written to file: who > users

Input redirection The commands that normally take their input from standard input can have their input redirected from a file: wc -l users wc -l < users

Processes Kernel starts a process for each program To see all the processes: ps PID TTY TIME CMD 26357 pts/5 00:00:00 tcsh 26558 pts/5 00:00:00 bash 32624 pts/5 00:00:00 ps

Process groups and pipelining Connect processes, by letting the standard output of one process feed into the standard input of another. That mechanism is called a pipe. Connecting simple processes in a pipeline allows to perform complex tasks without complex programs. $ls -l sort -k5n less Displays files in current directory sorted by file size

grep Searching plain-text data sets for lines matching a regular expression. Main uses: grep x matches entire line grep v matches all lines which do not contain a pattern grep ^pattern matches lines which start with pattern

Summary: your Linux toolbox Linux file system: inodes, hard and soft links File permissions Working with files Working with file contents I/O redirection Pipelining