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

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

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

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

CSE 390a Lecture 5. Intro to shell scripting

CSE 390a Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

CSE 391 Lecture 5. Intro to shell scripting

CSE 391 Lecture 3. bash shell continued: processes; multi-user systems; remote login; editors

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

CENG 334 Computer Networks. Laboratory I Linux Tutorial

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

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

Prof. Navrati Saxena TA: R. Sachan

Introduction to Linux Workshop 1

A Brief Introduction to the Linux Shell for Data Science

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

Week 2 Lecture 3. Unix

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

A Brief Introduction to Unix

bash startup files Linux/Unix files stty Todd Kelley CST8207 Todd Kelley 1

Essentials for Scientific Computing: Bash Shell Scripting Day 3

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

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

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

Unix Basics. UNIX Introduction. Lecture 14

CS/CIS 249 SP18 - Intro to Information Security

PROGRAMMAZIONE I A.A. 2015/2016

Unix Introduction to UNIX

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

Lecture 4. Log into Linux Reminder: Homework 1 due today, 4:30pm Homework 2 out, due next Tuesday Project 1 out, due next Thursday Questions?

Mills HPC Tutorial Series. Linux Basics I

The kernel is the low-level software that manages hardware, multitasks programs, etc.

Lab Working with Linux Command Line

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

Shell Start-up and Configuration Files

Topic 2: More Shell Skills

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

Introduction: What is Unix?

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

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

Exercise Sheet 2. (Classifications of Operating Systems)

Basic Unix Command. It is used to see the manual of the various command. It helps in selecting the correct options

Exploring UNIX: Session 3

Computer Systems and Architecture

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

CSC209H Lecture 1. Dan Zingaro. January 7, 2015

Shell. SSE2034: System Software Experiment 3, Fall 2018, Jinkyu Jeong

CS246 Spring14 Programming Paradigm Notes on Linux

Topic 2: More Shell Skills

Perl and R Scripting for Biologists

Introduction to Linux

Introduction. Let s start with the first set of slides

Lab 2A> ADDING USERS in Linux

Operating Systems. Copyleft 2005, Binnur Kurt

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 Unix May 24, 2008

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

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

Introduction to Linux

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

CS197U: A Hands on Introduction to Unix

CSCI 2132 Software Development. Lecture 5: File Permissions

Introduction to Linux. Roman Cheplyaka

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

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

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

5/20/2007. Touring Essential Programs

Review of Fundamentals. Todd Kelley CST8207 Todd Kelley 1

Commands are in black

DAVE LIDDAMENT INTRODUCTION TO BASH

Computer Systems and Architecture

The Linux Command Line & Shell Scripting

commandname flags arguments

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

Review of Fundamentals

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

More Raspian. An editor Configuration files Shell scripts Shell variables System admin

Practical 4. Linux Commands: Working with Directories

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

Basic UNIX commands. HORT Lab 2 Instructor: Kranthi Varala

28-Nov CSCI 2132 Software Development Lecture 33: Shell Scripting. 26 Shell Scripting. Faculty of Computer Science, Dalhousie University

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

Outline. Structure of a UNIX command

Working with Basic Linux. Daniel Balagué

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

Operating systems fundamentals - B10

Introduction To Linux. Rob Thomas - ACRC

Getting Started With Cpsc (Advanced) Hosted by Jarrett Spiker

Introduction of Linux

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

Lec 1 add-on: Linux Intro

UNIX Essentials Featuring Solaris 10 Op System

Chapter 1 - Introduction. September 8, 2016

: the User (owner) for this file (your cruzid, when you do it) Position: directory flag. read Group.

Introduction to UNIX Command Line

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

CSE II-Sem)

CSE 390a Lecture 1. introduction to Linux/Unix environment

-1- csh cd. cd alias!! ; set prompt=" pwd % " 16 cd. 17 cd.. 18 his /home% set prompt. alias. yasuoka : root :

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

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]

Transcription:

CSE 303 Lecture 4 users/groups; permissions; intro to shell scripting read Linux Pocket Guide pp. 19-20, 25-27, 61-65, 118-119, 176 slides created by Marty Stepp http://www.cs.washington.edu/303/ 1

Lecture summary discuss ethics/society reading #1 more I/O redirection, piping, combining commands user accounts, groups, and the super-user (root) file permissions introduction to shell scripting 2

Ethics/society reading #1 What is the difference between "open source" and "free? Is it important that we can see the source code? Could Microsoft still make any money if they went open source? What is a "fork"? Are forks good or bad, and why? Is Marty allowed to sell you an Ubuntu CD for $1? 3

Aliases command alias description assigns a pseudonym to a command alias name=command must wrap the command in quotes if it contains spaces Example: When I type q, I want it to log me out of my shell. Example: When I type ll, I want it to list all files in long format. alias q=exit alias ll="ls -la" Exercise : Make it so that typing q quits out of a shell. Exercise : Make it so that typing woman runs man. Exercise : Make it so that typing attu connects me to attu. Exercise : Make it so that typing banner on attu runs banner. 4

Recall: combined commands command1 > filename run command1 and write its output to filename instead of to console; >> appends rather than overwriting if the file already exists command1 < filename run command1 and read its input from filename instead of console command1 command2 run command1 and send its console output as input to command2 note that console input is not the same thing as parameters! Example: Find unique lines containing "secret" in all text files. grep secret *.txt uniq 5

Commands in sequence command1 ; command2 run command1 and then command2 afterward (they are not linked) command1 && command2 run command1, and if it succeeds, runs command2 afterward will not run command2 if any error occurs during the running of 1 Example: Make directory songs and move my files into it. mkdir songs && mv *.mp3 songs 6

More combining commands command1 `command2` run command2 and pass its console output to command1 as a parameter; ` is a back-tick, on the ~ key; not an apostrophe best used when command2's output is short (one line) Example: Create directory "stepp" (when logged in as stepp). mkdir `whoami` Why not whoami mkdir? Example: Display all files that were last modified during this year. ls -l grep `date +%G` 7

xargs command xargs description runs each line of its input as a command xargs allows you to repeatedly run a command over a set of lines often used in conjunction with find to process each of a set of files Example: Remove all evidence of my BitTorrent transfers. find ~ -name *.torrent xargs rm Exercise : List in long format all.txt files that contain the text "303", sorted in reverse alphabetical order. -rw------- -rw------- 1 stepp None 30300 Apr 6 10:07 todo.txt 1 stepp None 5434 Apr 6 10:07 ideas.txt 8

Users Unix/Linux is a multi-user operating system. Every program/process is run by a user. Every file is owned by a user. Every user has a unique integer ID number (UID). Different users have different access permissions, allowing user to: read or write a given file browse the contents of a directory execute a particular program install new software on the system change global system settings... 9

Groups command groups chgrp description list the groups to which a user belongs change the group associated with a file group: A collection of users, used as a target of permissions. a group can be given access to a file or resource a user can belong to many groups Every file has an associated group. the owner of a file can grant permissions to the group Every group has a unique integer ID number (GID). 10

File permissions command chmod umask description change permissions for a file set default permissions for new files types : read (r), write (w), execute (x) people : owner (u), group (g), others (o) on Windows,.exe files are executable programs; on Linux, any file with x permission can be executed permissions are shown when you type ls -l is it a directory? owner group others drwxrwxrwx 11

Changing permissions letter codes: chmod who(+-)what filename chmod u+rw myfile.txt (allow owner to read/write) chmod +x banner (allow everyone to execute) chmod ug+rw,o-rwx grades.xls (owner/group can read and write; others nothing) octal (base-8) codes: chmod NNN filename three numbers between 0-7, for owner (u), group (g), and others (o) each gets +4 to allow read, +2 for write, and +1 for execute chmod 600 myfile.txt (owner can read/write (rw)) chmod 664 grades.dat (owner rw; group rw; other r) chmod 751 banner (owner rwx; group rx; other x) 12

Super-user (root) command sudo su description run a single command with root privileges (prompts for password) start a shell with root privileges (so multiple commands can be run) super-user: An account used for system administration. has full privileges on the system usually represented as a user named root Most users have more limited permissions than root protects system from viruses, rogue users, etc. http://xkcd.com/149/ Example: Install the sun-java6-jdk package on Ubuntu. sudo apt-get install sun-java6-jdk 13

Shell scripts script: A short program whose purpose is to run other programs. a series of commands combined into one executable file shell script: A script that is executed by a command-line shell. bash (like most shells) has syntax for writing script programs To write a bash script (in brief): type one or more commands into a file; save it type a special header in the file to identify it as a script (next slide) enable execute permission on the file run it! 14

Basic script syntax #!interpreter written as the first line of an executable script; causes a file to be treated as a script to be run by the given interpreter (we will use /bin/bash as our interpreter) Example: A script that removes some files and then lists all files: #!/bin/bash rm output*.txt ls -l 15

Running a shell script by making it executable (most common): chmod u+x myscript.sh./myscript.sh by launching a new shell: bash myscript.sh by running it within the current shell: source myscript.sh advantage: any variables defined by the script remain in this shell (seen later) 16

.bash_profile every time you log in to bash, it runs the file ~/.bash_profile you can put any common startup commands you want into this file useful for setting up aliases and other settings Exercise : Make it so that our q and L aliases from earlier become persistent, so that they will work every time we run a shell. Exercise : Make it so that whenever you try to delete or overwrite a file during a move/copy, you will be prompted for confirmation first. 17

echo command echo description produces its parameter(s) as output (the println of shell scripting) Example: A script that prints the time and your home directory. #!/bin/bash echo "This is my amazing script!" echo "Your home dir is: `pwd`" Exercise : Make it so that whenever I log in to attu, it: clears the screen displays the current date: The time is: 04/06 10:40 shows me an ASCII cow welcoming my user name 18