UNIX Concepts COMPSCI 386

Similar documents
Welcome to Linux. Lecture 1.1

INTRODUCTION TO LINUX

CS246 Spring14 Programming Paradigm Notes on Linux

Perl and R Scripting for Biologists

Chapter Two. Lesson A. Objectives. Exploring the UNIX File System and File Security. Understanding Files and Directories

Brief Linux Presentation. July 10th, 2006 Elan Borenstein

Essential Unix and Linux! Perl for Bioinformatics, ! F. Pineda

Overview of Unix / Linux operating systems

Introduction to Linux

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

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

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

Unix System Architecture, File System, and Shell Commands

System Programming. Introduction to Unix

Unix Handouts. Shantanu N Kulkarni

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

Filesystem Hierarchy and Permissions

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 Essentials. Programming and Data Structures Lab M Tech CS First Year, First Semester

EECS2301. Lab 1 Winter 2016

Filesystem Hierarchy and Permissions

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

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

CISC 220 fall 2011, set 1: Linux basics

*nix Crash Course. Presented by: Virginia Tech Linux / Unix Users Group VTLUUG

Unix/Linux: History and Philosophy

Introduction to Linux

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

Introduction to Cygwin Operating Environment

Introduction to Linux

UNIX Kernel. UNIX History

Introduction to Linux

Introduction to Linux

Introduction to Linux. Roman Cheplyaka

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

Unix to Linux. CS 3113 Fall 2018 Dr. Christan Grant

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

An Introduction to Unix Power Tools

22-Sep CSCI 2132 Software Development Lecture 8: Shells, Processes, and Job Control. Faculty of Computer Science, Dalhousie University

Chapter 1 - Introduction. September 8, 2016

Chapter-3. Introduction to Unix: Fundamental Commands

Computer Systems and Architecture

Today. Operating System Evolution. CSCI 4061 Introduction to Operating Systems. Gen 1: Mono-programming ( ) OS Evolution Unix Overview

Linux & Shell Programming 2014

(a) About Unix. History

Computer System Management - Unix/Linux

EECS 2031E. Software Tools Prof. Mokhtar Aboelaze

UNIX System Programming Lecture 3: BASH Programming

Introduction to Shell Scripting

The UNIX Operating System. HORT Lecture 2 Instructor: Kranthi Varala

Welcome to getting started with Ubuntu Server. This System Administrator Manual. guide to be simple to follow, with step by step instructions

Filesystem and common commands

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

The Unix Shell & Shell Scripts

Introduction to Linux Basics

Introduction to Linux Part I: The Filesystem Luca Heltai

Introduction. Let s start with the first set of slides

Introduction of Linux

CS 307: UNIX PROGRAMMING ENVIRONMENT REVIEW FOR EXAM 1

Introduction: What is Unix?

Unix Filesystem. January 26 th, 2004 Class Meeting 2

Classic Systems: Unix and THE. Presented by Hakim Weatherspoon

Linux Essentials. Smith, Roderick W. Table of Contents ISBN-13: Introduction xvii. Chapter 1 Selecting an Operating System 1

Operating System Labs. Yuanbin Wu

Unix/Linux Operating System. Introduction to Computational Statistics STAT 598G, Fall 2011

Essential Unix (and Linux) for the Oracle DBA. Revision no.: PPT/2K403/02

System Administration

Introduction and Overview Getting Started

PROGRAMMAZIONE I A.A. 2015/2016

CS108 Software Systems: UNIX. Fall 2011

Introduction to Supercomputing

Linux Session Part I. Kesavan M

PESIT Bangalore South Campus

Linux Systems Administration Getting Started with Linux

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Introduction to Linux for QSS/OASIS System Administrators and System Operators

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

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

Appendix A GLOSSARY. SYS-ED/ Computer Education Techniques, Inc.

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

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

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

CSCI 2132 Software Development. Lecture 2: Introduction to UNIX and Unix-like Operating Systems

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

Chp1 Introduction. Introduction. Objective. Logging In. Shell. Briefly describe services provided by various versions of the UNIX operating system.

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Unix Introduction to UNIX

Hands-on Keyboard: Cyber Experiments for Strategists and Policy Makers

Chap2: Operating-System Structures

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?

CS2028 -UNIX INTERNALS

Filesystem Hierarchy Operating systems I800 Edmund Laugasson

Linux Essentials Objectives Topics:

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

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

Introduction to Unix: Fundamental Commands

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

CS 300. Data Structures

CS370 Operating Systems

Transcription:

UNIX Concepts COMPSCI 386

Topics History of C and UNIX The GNU Project Linux Command-Line Basics UNIX-Style File System

Multics Multiplexed Information and Computing Service Time-sharing system for mainframes (1965) virtual memory and other modern OS features MIT, Bell Labs, and General Electric First (?) OS written in a high-level language (PL/1). Influential but not a commercial success. Ken Thompson and Dennis Ritchie worked on the project until Bell Labs dropped out. (Thompson at Google since 2006, where he co-invented Go.) They continued on their own. Kernighan and others at Bell Labs joined the effort. Designed UNIX for DEC PDP-7. Later reimplemented on the PDP-11.

UNIX The goal was to create a time-sharing OS with a simple UI and simple components that can be arranged and composed in a variety of ways. Philosophy in a nutshell: modularity. Write programs that do one thing and do it well. Write programs to work together. Write programs to handle text streams, because that is a universal interface. (McIlroy) The 17 Rules Originally written in assembly, but a high-level language would be needed for its proper development.

C First, Ken Thompson invented B. a typeless, stripped-down version of BCPL compiler squeezed into 8K bytes of memory Then C was born as B-with-types. Easy to retarget C compiler: made UNIX highly portable sparked its prominence in industry and academia C was standardized by ANSI in 1989.

C Why are almost all operating systems written in C? Speed Code maps efficiently to machine instructions. no threads, templates, nested functions, function or operator overloading, exception handling; limited support for OOP. Not much runtime support is needed. no dynamic type checking no bounds checking or garbage collection Low-level access to memory (and hardware) thanks to weakly typed pointers

The GNU Project UNIX was proprietary, licenced to universities and corporations by A&T. In 1984, Richard Stallman (* * *) at the MIT AI Lab launched the GNU project to develop a free UNIXlike OS. He wrote gcc, emacs, and other GNU tools that are still in widespread use. Created the Free Software Foundation to sponsor GNU development and pursue free software ideals.

Open Source Free software: like free speech or free beer? The freedom to view, copy, modify, and redistribute source code without having to pay royalties or other fees. Open source movement Best way to produce safe and reliable software? Enlist the cooperation of developers from around the world in a free exchange of ideas, opinions, and code. Stallman wrote the first copyleft licence (GNU GPL)

Linux GNU's kernel was never finished. Linux released in 1991. The goal was to create a UNIX-like OS for PC. Just a kernel, but can be packaged with GNU tools and libraries for complete OS, called properly GNU/Linux. There are now hundreds of distributions. Linux kernel with GNU tools and libraries, third-party software, package manager, desktop environment.

User Interfaces batch, shell (CLI), GUI Two strategies for implementing a shell: Interpret and execute each command. (DOS) If user types rm myfile.txt, shell makes necessary system calls. Does not interpret the command. Just invokes a system program to perform the work. (UNIX) If user types rm myfile.txt, the shell invokes a system program named rm with myfile.txt as a parameter. Two major advantages to this approach.

Bourne Shell (1977) /bin/sh expressive scripting language can use scripts as filters I/O redirection and pipes globbing and command substitution scripts invoked as commands by their filename synchronous/asynchonous execution of commands

C Shell (1979) /bin/csh (or improved version: /bin/tcsh) scripting language with C-like syntax filename and command completion history, aliases, and other features for interactive use

Korn Shell (1983) /bin/ksh job control command aliasing command history better for interactive work than C shell, but had to be licensed from AT&T

Bash Shell (1989) /bin/bash Bourne-Again SHell Written for GNU Project Default shell for Linux and macos

Command-Line Basics What shell am I using? Navigating the file system Viewing and finding files File permissions Copying and moving files Grepping Pipes and redirection Hard links and soft links

BASH Variables Environment variables inherited by child processes /etc/bash.bashrc (for interactive non-login shells) SHELL, USER, HOME, PATH, PWD Shell variables not inherited by child processes ~/.bashrc (for interactive non-login shells) PS1, BASH_VERSION, HISTSIZE

What Shell Am I Using? > printenv SHELL /bin/bash > echo $SHELL /bin/bash > ps $$ PID TTY STAT TIME COMMAND 3877 pts/1 Ss 0:00 /bin/bash > ps -p $$ PID TTY TIME CMD 3877 pts/1 00:00:00 bash We can use ps to obtain info about all processes in the system.

Navigating the File System Listing directory contents with ls options lapf man ls pwd cd ls.. ls../.. ls / ls ~ Change to parent, root, and home without specifying absolute paths.

Filesystem Hierarchy Standard Defines directory structure for UNIX-like systems. Most Linux distributions are FHS-compliant.

Navigating the File System /bin (command binaries) /boot (files used by the kernel during start-up) /dev (device files) /etc (system configuration files) /home (home directories for individual users) /lib (shared libraries and kernel modules) /lost+found (recovered files, as after system crash) /media (mount point for removable media)

Navigating the File System /mnt (mount point for temporary file system) /opt (add-on software not part of default installation) /proc (virtual file system containing system info) /root (home directory for system administrator) /sbin (binaries for system maintenance and admin tasks) /tmp (temporary files) /usr (user-land programs and data) /tmp (temporary files, like lock files) /var (system log files)

Viewing Files cat /etc/shells cat bash_lab/episode4.txt more or less

Determining File Types file /etc/shells file /etc/p* file /bin/cat

Finding Files

Finding Files

File Permissions - rwx r-x --x type user group other

File Permissions Do a long listing after each of the following: cd art chmod u-w 1* chmod g+w [2-4].jpg chmod u=rwx,go=r 5* chmod 751*

File Permissions

File Permissions Default file creation mask umask umask -S Type umask 135 and touch a file. umask is a built-in command. man umask

Copying and Moving Files cp /etc/shells. cp /etc/shells ~ cp -r bash_lab/art ~ Try to remove art.

Grepping Using grep the most common UNIX filter. grep womp episode4.txt grep the droids episode4.txt grep sand episode4.txt grep -c LUKE episode4.txt grep [A-Z]-[0-9] episode4.txt grep ^Eight episode4.txt

Pipes and Redirection A pipe connects one process to another. Redirection connects a process to a file. grep ^Luke episode4.txt grep Ben grep droid episode4.txt wc -l man less less ls /etc > etc history > history

Pipes and Redirection Exercise Write a C program that prompts the user for two integers and displays the average. Compile and test it. Create a text file with input for the program. Run the program with input redirected to the file. Redirect the output to a file.

Hard Links Create directories tempdir1 and tempdir2. Create a text file in tempdir1 and display contents.

Hard Links Make a hard link and display the link count. Move the link to tempdir2 and delete the text file. Change to tempdir2. cat indignation Surprised?

UNIX File System Directories do not contain files. That's an illusion. A directory is a file containing a list of (name, inum) pairs. art 1409792 episode4.txt 1391495 episode5.txt 1391768 Each inum is an index into a table of inodes. Do a directory listing with i and ail options.

UNIX File System The inode table contains inodes. protection mode owner and group file size link count timestamps direct blocks indirect blocks double indirect triple indirect Note that file name not stored. DATA DATA DATA DATA DATA DATA DATA DATA

UNIX File System /usr/src/linux-headers-4.4.0-34/include/linux/fs.h struct inode { umode_t i_mode; unsigned short i_opflags; kuid_t i_uid; kgid_t i_gid; unsigned int i_flags; }

Hard Links ln episode4.txt e4 art 1409792 episode4.txt 1391495 episode5.txt 1391768 e4 1391495 Move link to another directory. Now you can find the file with -inum option.

Soft Links Make a soft (symbolic) link. Move soft link to tempdir2. Remove original file (yoda). Now in tempdir2, try: cat slink.

Hard vs. Soft Links Which is like a Windows shortcut? Hard links more space efficient faster access to link target Soft links can link to directories can link across file systems