CS197U: A Hands on Introduction to Unix

Similar documents
CS197U: A Hands on Introduction to Unix

Unix Filesystem. January 26 th, 2004 Class Meeting 2

CS197U: A Hands on Introduction to Unix

Computer Systems and Architecture

Introduction to Unix: Fundamental Commands

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

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

Embedded Linux Systems. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

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

Commands are in black

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

Computer Systems and Architecture

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

Introduction to the Linux Command Line

Working with Basic Linux. Daniel Balagué

Chapter-3. Introduction to Unix: Fundamental Commands

commandname flags arguments

Filesystem Hierarchy and Permissions

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

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

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

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

CSCI 2132 Software Development. Lecture 4: Files and Directories

Overview of the UNIX File System

Linux Command Line Primer. By: Scott Marshall

Introduction to UNIX command-line

Filesystem Hierarchy and Permissions

CS370 Operating Systems

INTRODUCTION TO LINUX

Getting your department account

A Brief Introduction to Unix

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

Perl and R Scripting for Biologists

CSC209. Software Tools and Systems Programming.

CS Fundamentals of Programming II Fall Very Basic UNIX

Linux Systems Administration Getting Started with Linux

Introduction to Linux. Roman Cheplyaka

A Brief Introduction to the Linux Shell for Data Science

Introduction to Linux

Introduction to Linux

EECS Software Tools. Lab 2 Tutorial: Introduction to UNIX/Linux. Tilemachos Pechlivanoglou

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 files searching, and other interrogation techniques

Introduction: What is Unix?

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

Introduction to Linux Part I: The Filesystem Luca Heltai

Overview of the UNIX File System. Navigating and Viewing Directories

Introduction to Linux

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

Introduction to Linux

UNIX File Hierarchy: Structure and Commands

CSE 390a Lecture 3. Multi-user systems; remote login; editors; users/groups; permissions

1 Installation (briefly)

CS246 Spring14 Programming Paradigm Notes on Linux

Introduction to Linux

CS 215 Fundamentals of Programming II Spring 2019 Very Basic UNIX

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

CS Unix Tools. Lecture 2 Fall Hussam Abu-Libdeh based on slides by David Slater. September 10, 2010

Chap2: Operating-System Structures

Using UNIX. -rwxr--r-- 1 root sys Sep 5 14:15 good_program

Files and Directories

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

An Introduction to Cluster Computing Using Newton

Operating Systems. Copyleft 2005, Binnur Kurt

The Command Line. Matthew Bender. September 10, CMSC Command Line Workshop. Matthew Bender (2015) The Command Line September 10, / 25

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

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

Basic Survival UNIX.

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

Outline. Structure of a UNIX command

INTRODUCTION TO BIOINFORMATICS

Course 144 Supplementary Materials. UNIX Fundamentals

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

EECS2301. Lab 1 Winter 2016

CSC209. Software Tools and Systems Programming.

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Practical Session 0 Introduction to Linux

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

CMSC421: Principles of Operating Systems

CS4350 Unix Programming. Outline

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Introduction to UNIX Command Line

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

Student Remote Login Procedure (see picture below): 1. Start SSH Secure Shell 2. Click the computer icon (4 th on the toolbar) 3.

THE HONG KONG POLYTECHNIC UNIVERSITY Department of Electronic and Information Engineering

Lab Working with Linux Command Line

Files (review) and Regular Expressions. Todd Kelley CST8207 Todd Kelley 1

M.C.A. (Sem.-lll) (CBCS) Examination November CCA-3003 Operating System and LinuxlUnix programming

This lab exercise is to be submitted at the end of the lab session! passwd [That is the command to change your current password to a new one]

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

CSE 390a Lecture 4. Persistent shell settings; users/groups; permissions

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

Operating Systems and Using Linux. Topics What is an Operating System? Linux Overview Frequently Used Linux Commands

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

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

5/20/2007. Touring Essential Programs

CS 307: UNIX PROGRAMMING ENVIRONMENT FIND COMMAND

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

National University of Computer and Emerging Sciences Operating System Lab - 02 Lab Manual

Transcription:

CS197U: A Hands on Introduction to Unix Lecture 3: UNIX Operating System Organization Tian Guo CICS, Umass Amherst 1

Reminders Assignment 2 is due THURSDAY 09/24 at 3:45 pm Directions are on the website If you have questions about the assignment I ll be in the Edlab Thursday from 1:00 to 3:00 pm Email me If you plan to withdraw from the class, come talk to me. 2

Quick Quiz head - n X [file] --- prints out the top X lines of file grep string [file] --- print only the lines in file that contain string What is the difference between these commands? head - n 100 file.txt grep UMass grep UMass file.txt head - n 100 Are these the same? Would one run faster than the other? sort lots_of_data.csv grep 1973 grep 1973 lots_of_data.csv sort 3

Quick Quiz Write the commands to: Answers: grep print *.cpp head - n 5 sort phonenumbers.txt >> contacts.txt Display the first five lines that contain the word print in any.cpp file in the current directory Sort the contents of the file phonenumbers.txt and append it to the file contacts.txt Describe a situation when you would use the head utility instead of cat Describe a situation when you would use the less utility instead of cat Describe a situation when you would use the cat utility instead of less 4

Working with Paths elnux3> pwd /home/username/1/2/3/4/5/6/7/8 What does this do? What does it not copy? elnux3> cp../../*../../../../ What s the difference to this? elnux3> cp r../../*../../../../ What is the difference between these commands? elnux3> cd elnux3> cd. elnux3> cd ~ Use. and ~ with other commands like cp Doesn t copy any sub directories in 6 Copies everything in 6 and below (7 and 8) 5

Useful tips head - n 3 days.txt sort uniq grep c Friday If the output of a lot of piped commands doesn t make sense to you decompose: head - n 3 days.txt less head - n 3 days.txt sort less head - n 3 days.txt sort uniq less Look at intermediate output after each pipe also useful for debugging 6

Search for a command in history Use UP and DOWN keys in terminal Takes too long to find a command used a long time ago history less Use /<search_string>, type `n to go to next copy command Good, but still slow history grep <search_string> Use!<number> to execute. Note: <number> is the number listed to the left of the command. Use reverse incremental search (in bash shell only) Ctrl + r, start typing command Type Ctrl + r again to find next match Fast! 7

Password-less SSH login Connect to remote hosts without entering your password every time e.g., connect to elnux machines in Edlab From a Unix shell only (Linux or Mac OS X) Create SSH keys run ssh- keygen - t rsa copy ~/.ssh/id_rsa.pub to ~/.ssh/authorized_keys on remote host scp ~/.ssh/id_rsa.pub username@elnux1.cs.umass.edu:~/.ssh/authorized_keys ~ is short for your home directory From Windows Different procedure for putty http://www.tecmint.com/ssh-passwordless-login-with-putty/ 8

The plan... Last time: Overview of useful Linux commands reading files: cat, head, tail, less, grep editing files: vim, sort, uniq manipulating files: mv, cp, rm This time we will: Learn about OS structure Explore the Linux file system Learn about file permissions 9

In this class: Discuss basics of OS structure and function If you re interested in more details, consider taking the Operating Systems class! Discuss role of operating system and responsibilities of the Linux kernel 10

Things the OS does Layer between user applications and hardware Goal: Hide complexity of hardware from applications/users Responsible for: Taking care of multitasking (time-sharing) in an intelligent way Managing resources (memory, network, CPU, devices, etc) Separation (security, stability) 11

Basic concept: Processes Instance of a program, which is being executed Isolated from other processes ls All processes appear to execute simultaneously OS makes it seem like each process is running alone Memory Code Other State 12

Basic concept: Processes Processes don t need to reserve time from other processes; each one executes as if it had its own CPU Isolated from other processes A process s memory is isolated and protected from other processes. - A process accesses the disk, network, etc with system calls System ls Memory Code firefox Memory Code Other State Other State

System ls firefox Memory x Code Other State Memory Code Other State If one application crashes or misbehaves, this should not affect other processes 14

How the system works The OS must make each process appear to have its own CPU, address space, etc The OS uses abstract APIs to access storage, network, devices, etc Hardware can change, OS still works Any number of processes can exist But hardware only provides fixed resources (one CPU, one memory space, one disk, and low-level devices) 15

The Kernel The Kernel is a master program that manages resources The Kernel executes directly on the hardware The Kernel then runs all other processes Process Process Process Kernel Hardware Memory Devices CPU Disk 16

Main kernel tasks Implement multitasking Implement memory management and protection Device interfacing Translate high-level system calls into low-level device commands 17

The plan... This time we will: Learn about OS structure Explore the Linux file system Learn about file permissions 18

Filesystem Abstraction of actual storage device Data isn t stored as files, but as blocks Filesystem makes organization and use easier Implements a named, hierarchical storage system /bin bash ls passwd /home tian cscf /usr /bin man /src /kernel Filesystem Divides up a single volume into many directories Disk Each stores different types of information 19

Filesystem basics A regular file is a string of bytes File extension (e.g..txt or.doc ) is only meaningful to the user A directory contains other files or directories Special files, such as device files also exist 20

Filesystem directories Directories allow the filesystem to be hierarchical Directories can contain many other directories, but all directories have only one parent The directory / is the root directory 21

Paths Paths name a file Either relative to the current directory cs197u/<username>/file.txt From an absolute location /courses/cs100/cs197u/cs197u/assignments/assign- 2 Paths starting with / are absolute paths, from the root directory: Paths starting with ~/ are relative to the user s home directory Can refer to another user s home directory with: ~username/ All other paths are relative to the current directory 22

Filesystem Tour - / /bin/ - executable files /opt/ - third-party software /sbin/ - Privileged Executables /sys/ - Kernel, device drivers, etc /dev/ - Devices /usr/ - other OS programs and data /etc/ - System configuration /var/ - Logs, databases, rapidlychanging files /home/ - User home directories /lib/ - libraries 23

Filesystem Tour - /etc/ - configuration files /etc/rc, /etc/rc.d/ - System startup program; started by kernel during boot process /etc/passwd, /etc/passwd.db - user info, minus passwords (usually) /etc/shadow.passwd - user info, with encrypted passwords /etc/groups - group info a lot of.conf files 24

Filesystem Tour - /opt/, /usr/ - user apps /.../bin/ - executable files /.../sbin/ - Executable files which execute at higher privileges /.../lib/ - libraries /.../local/ - local additions to standard distributions /.../share/ - Additional information (examples, etc.) /.../libexec/ - Additional private configuration /.../src/ - source code /.../man/ - man pages 25

Filesystem Tour - /home/ - user directories Directories named after individual users sometimes has bin/, lib/,... subdirectories User-specific configuration data files often start with..profile - executed when starting a shell.ssh/ - ssh config data other. files for specific programs 26

Filesystem Tour - /dev/ - devices Devices appear as files in UNIX Here you ll find hard drives, CD drives, etc. Don t need to be physical devices, some have special functions /dev/null - Null device, ignores all reads, discards all writes /dev/zero - produces zeros when read /dev/random, /dev/urandom - produces random numbers when read Other devices do specific things (hard drives can be directly read) 27

Looking for things in the file system find prints the path to a file find <dir> name *.txt print Use for finding a specific file in some directory Very useful, many flags locate prints the path to a file; very good for finding system files > locate passwd /etc/passwd /etc/alternatives/vncpasswd /etc/pam.d/chpasswd /etc/pam.d/passwd /etc/security/opasswd /usr/nx/scripts/restricted/nxpasswd.sh /usr/bin/gpasswd /usr/bin/grub- mkpasswd- pbkdf2 /usr/bin/kpasswd 28

The plan... This time we will: Learn about OS structure Explore the Linux file system Learn about file permissions 29

File ownership Each file is owned by a group and a user Use ls -l to see file ownership details A user is an account for an individual person root is a special account for the system administrator Each file has one user that owns it A group is a collection of users A group can hold multiple users Each user can be in multiple groups Type groups to see what groups you are a part of Used to let a user share files with others Each file is associated with one group 30

File permissions Can control access for the user, group, or world (everyone else) Possible actions: Read file contents Write to a file (edit or overwrite) Execute a program or open a directory read write exec user Y Y N group Y N N user group world = rw- r-- --- world N N N 31

" Directory permissions Directories have same type of permission Execute is permission to open the directory Only applies to directory itself -- individual files will have own settings read write exec user Y Y Y group Y N Y = rwx r-x r-x world Y N Y read write exec user Y Y Y group Y Y Y = rwx rwx rwx world Y Y Y 32

Setting Permissions Command to change: chmod <setting> <filename> <setting>: <x><y><z> <x>: u - user <y>: + add " <z>: r - read g - group - remove w - write o - world a - all x - execute Examples: chmod u+r file.txt chmod g-x file.txt chmod o-w file.txt Add user read permission for file.txt Remove group execute permission for file.txt Remove world write permission for file.txt 33

Setting Permissions Command to change: chmod <setting> <filename> <setting>: <x><y><z> <x>: u - user g - group o - world a - all Exercises: <y>: + add " - remove <z>: r - read w - write x - execute Add user & group write permission for file.txt Remove world read,write & execute permission for file.txt Add world,group & user read,write and execute permission for file.txt 34

Setting Permissions Command to change: chmod <setting> <filename> <setting>: <x><y><z> <x>: u - user g - group o - world a - all Exercises: <y>: + add " - remove <z>: r - read w - write x - execute chmod gu+w file.txt chmod o-rwx file.txt chmod ogu+rwx file.txt chmod a+rwx file.txt Add user & group write permission for file.txt Remove world read,write & execute permission for file.txt Add world,group & user read,write and execute permission for file.txt 35

Setting Permissions Permissions can also be represented as numbers Letters: rw- r-x --- Binary flags: Decimal: 110 101 000 6 5 0 Permissions code: 650 Command to change permissions: chmod 650 filename 36

37 37 Letters: r-- r-- rwx Binary flags: Decimal: 100 100 111 4 4 7

Letters: rwx rwx rwx Binary flags: Decimal: 111 111 111 7 7 7 38

Summary An OS is responsible for Allocating resources to processes Providing protection Coordinate access to I/O devices Remember Assignment 2 is Due THURSDAY before class! The Linux filesystem has a lot of stuff in it As a user you ll generally only have to deal with your home directory Linux provides a set of file permissions to limit access See Chapter 5 in book for more advanced options Changing what user owns a file, what group owns a file, changing default permissions, etc. 39

Lecture 3 review Command history chmod find locate Description Print a list of previously run commands Change permissions for a directory or file Print a path to a file Print a path to a file 40