2.0.0.3 – Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 1 2.0.0.3.2 Introduction to the Shell – Session 2 · Permissions · Users.

Slides:



Advertisements
Similar presentations
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Advertisements

NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Linux File & Folder permissions. File Permissions In Ubuntu, files and folders can be set up so that only specific users can view, modify, or run them.
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
1 CSE 390a Lecture 4 Persistent shell settings; users/groups; permissions slides created by Marty Stepp, modified by Jessica Miller
1 CSE 303 Lecture 4 users/groups; permissions; intro to shell scripting read Linux Pocket Guide pp , 25-27, 61-65, , 176 slides created by.
Linux+ Guide to Linux Certification, Second Edition
Linux+ Guide to Linux Certification, Second Edition
Guide To UNIX Using Linux Third Edition
Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Introduction to Unix – CS 21 Lecture 5. Lecture Overview Lab Review Useful commands that will illustrate today’s lecture Streams of input and output File.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
Introduction to Linux Workshop February Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT.
BILKENT UNIVERSITY DEPARTMENT OF COMPUTER TECHNOLOGY AND INFORMATION SYSTEMS CTIS156 INFORMATION TECHNOLOGIES II CHAPTER 10: ADVANCED FILE PROCESSING.
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface (or Terminal) What is the filesystem tree.
Chapter Nine Advanced Shell Scripting1 System Programming Advanced Shell Scripting.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Guide To UNIX Using Linux Fourth Edition
The “File System” Under UNIX, (almost) everything is a “file”: –Normal files –Directories –Hardware –Sockets –Pipes Things that are not files: –Users –Groups.
An Introduction to Unix Shell Scripting
Introduction to Computer Organization & Systems Topics: Intro to UNIX COMP John Barr.
Basic unix commands that everyone should know (Even if you have a mac) Slightly more advanced:
CS 2061 Shells Also known as: Unix Command Interpreter.
File Permissions. What are the three categories of users that apply to file permissions? Owner (or user) Group All others (public, world, others)
Linux+ Guide to Linux Certification, Second Edition
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
Linux+ Guide to Linux Certification, Third Edition
LINUX programming 1. INDEX UNIT-III PPT SLIDES Srl. No. Module as per Session planner Lecture No. PPT Slide No. 1.Problem solving approaches in Unix,Using.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
Unix/Linux cs3353. The Shell The shell is a program that acts as the interface between the user and the kernel. –The shell is fully programmable and will.
I/O and Redirection. Standard I/O u Standard Output (stdout) –default place to which programs write u Standard Input (stdin) –default place from which.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
Linux file system "On a UNIX system, everything is a file; if something is not a file, it is a process." Sorts of files (on a Linux system) Directories:
40 Years and Still Rocking the Terminal!
Linux+ Guide to Linux Certification, Third Edition
Linux+ Guide to Linux Certification, Third Edition
Lab 3 + Using the Terminal 1. "Under Linux there are GUIs (graphical user interfaces). where you can point and click and drag, and hopefully get work.
UNIX shell environments CS 2204 Class meeting 4 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Introduction to Programming Using C An Introduction to Operating Systems.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Executable scripts. So far We have made scripts echo hello #for example And called it hello.sh Run it as sh hello.sh This only works from current directory?
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
1 Day 18 Bash and the.files. 2 The.files ls shows you the files in your directory –Or at least most of them. –Some files are hidden. Try: ls –a –This.
Linux Commands C151 Multi-User Operating Systems.
CSCI 330 UNIX and Network Programming Unit III Shell, Part 1.
– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Introduction to the Shell – Session 3 · Job control · Start,
Linux+ Guide to Linux Certification, Second Edition
Agenda The Bourne Shell – Part I Redirection ( >, >>,
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
Learning Unix/Linux Based on slides from: Eric Bishop.
Linux Administration Working with the BASH Shell.
Agenda Customizing a Unix/Linux account Environment Introduction to Start-up Files (.bash_profile,.bashrc,.profile,.kshrc) Safe Methods for Changing Start-up.
Introduction to Shells
Linux file system "On a UNIX system, everything is a file;
Some Linux Commands.
The Linux Operating System
Shell Script Assignment 1.
CSE 303 Concepts and Tools for Software Development
Basic UNIX OLC Training.
Persistent shell settings; users/groups; permissions
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Presentation transcript:

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users and groups · Who can do what and how to control it · Customizing your environment · Changing the shell prompt · Aliases · Environment variables · Saving customizations · Pipes and redirection · Controlling input and output · Running a series of commands · Running programs on the command line

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 2 UNIX Users and Groups · Every file/directory belongs to a user and a group · People logged on to UNIX systems are users · Check who you are logged on as with · Change who you are logged on as with whoami su

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 3 UNIX Users and Groups · Check which groups you belong to with · See what user and group a file belongs to with ls –l or stat (as in ) groups Group users Every user at GSC belongs to the group “users”, and this is the default group ownership for any file created. GroupUse r

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 4 UNIX Users and Groups: chgrp · Users (except root) cannot change which user owns a file · Change the group that a file (or directory) belongs to with -R: change recursively (all subdirectories and files) chgrp

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 5 The Permissions System: reading, writing, and executing · Permissions refer to the type of access that users have to files · Allows files to be private, public, read-only, etc. · There are three types of access possible: · Read (ability to see the contents of a file, or list the contents of a directory) · Write (ability to modify or delete a file, or create files in a directory) · Execute (ability to run the file as a program – eg. Perl scripts need to be executable – or enter a directory) · Permissions are set individually for: · User · Group · All users

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 6 The Permissions System: reading, writing, and executing · Read, write, and execute permissions for user, group, and all users are specified as “r”, “w” and “x” (if the permission is given) or “-” (if the permission is denied) For all users For group For use r

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 7 Changing Permissions: chmod · If you own a file, change permissions using · Specify: chmod chmod [ugoa][+- =][rwx] Who to modify permissions for: u = user g = group o = other (all users) a = all (u,g, and o) Whether to give or take permission: + = give - = take away = = these are the only permission s What permission to modify: r = read w = write x = execute Other options: -R apply recursively

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 8 Changing Permissions: chmod examples · Make a file private (only you can see it): -rw chmod og-rw or chmod og= · Make a file public (everyone can modify it): -rw-rw-rw- chmod a+rw · Make a directory private (only you can view it’s contents): drwx chmod og-rwx or chmod og= · Make a directory usable by anyone (anyone can add files to it): drwxrwxrwx chmod a+rwx · Make a file executable: -rwxr-xr-x chmod a+x

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 9 Changing Permissions: chmod and umask · You can also use a set of numbers to set permissions eg. chmod 644 = -rw-r--r-- · Specify default permissions for all newly created files with umask eg. umask 022 = -rw-r--r– (files) -rwxr-xr-x (directories)

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 10 Other file attributes: chattr · In addition to specifying permissions, other file attributes can be set with · eg. set the file so it cannot be deleted, so it’s access time is not updated, or so that it is stored in compressed form. chattr

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 11 Customizing your Environment: Environment variables · Environment variables store information about how your shell should look and behave, where to find things, particular program settings, etc. They are used by programs running in the shell. · See what environment variables are currently set with · Set environment variables with =“new value” · Delete environment variables with printenv unset

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 12 Setting the Prompt: PS1 · The environment variable PS1 stores what is displayed at the prompt · Use special characters: \d date \t and time \h hostname \u username \w current directory · Get colourful! To specify colour, bracket the colour code between a “\e[“ (or “\033[“) and an “m” 30Black 31Red 32Green 33Yellow 34Dark blue 35Purple 36Light blue 37White Word wrapping isn’t working! When modifying colours in PS1, surround the color specifications with “\[“ and “\]” to tell the shell that text doesn’t take up any space on the prompt.

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 13 Specifying Where to Look for Programs: PATH · The PATH variable stores a list of directories where the shell and other processes should look for programs · Each entry is separated by “:” · Start your path with “.” to run scripts without specifying “./”

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 14 Specifying Where to Look for Directories: CDPATH · CDPATH is like PATH, but instead of specifying where to look for programs, it specifies where to look for directories · Be careful, it can be dangerous…. always put “.” first!

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 15 Other Environment Variables · HISTSIZE specifies the number of commands to keep in the history · PRINTER specifies the printer name · PWD stores the current directory (used by “pwd”) · OLDPWD stores the previous directory (used by “cd –”) · LS_COLORS specifies colours to display different file/directory types as (used by “ls –color”) · Various programs require other environment variables · BLAST · SRS · Java · Perl · Etc….

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 16 Defining Commands: aliases · An alias is a short form of a command that can save on typing · View and assign aliases with · To use the “normal” command, not the alias, use \ eg. “\ls” lists with no colour etc. alias

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 17 Customizing your Environment: Configuration at startup · Customizations are lost when you logout · To save them, put them in one of your configuration files: ·.bash_profile (/home/ /.bash_profile) is run every time you log on ·.bashrc (/home/ /.bashrc) is run every time you open a shell other than the login shell · “export” the variables so you can see and access them Oops! Careful…. If you do something wrong (like make text white on white) it can be difficult to fix · Test everything before putting it in.bashrc or.bash_profile · Keep an extra terminal window that was opened BEFORE you made the changes, so you can use that terminal to fix mistakes

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 18 Input, Output, and Error · Data can be transferred (eg. between commands) in the shell using three streams: · Standard input (STDIN in Perl): Input to a process, by default from the keyboard · Standard output (STDOUT in Perl): Output from a process, by default to the terminal window · Standard error (STDERR in Perl): Another stream of output from a process, by default to the terminal window · eg. · cat takes a file or text from the terminal as standard input, writes the file contents to standard output (the terminal) · Error messages from commands are written to standard error · Perl scripts by default write to standard output

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 19 Redirecting Input, Output, and Error: >, >, 2>, $> · Redirect standard input to a file with < · Redirect standard output to a file with > or 1> · Redirect standard error to a file with 2> · Redirect BOTH standard output and error to a file with $> · Redirect standard output to append to a file with >> /dev/null A useful “file” to redirect to is /dev/null: anything redirected here just disappears. Good for programs that produce a lot of verbose messages that you don’t need to see or keep. stdout append stdout stderr

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 20 Example: Perl output · It is good practice to separate “real” output from error messages when running Perl scripts

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 21 Running a Series of Commands: pipes · To put the standard output of one command directly into the standard input of another, use a pipe “|” (on the keyboard above the “\”) · You can do this as many times as you like on one line – especially useful for command line tools like grep, cut, sort, wc, etc. (see session )

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session 2 22 Running Programs on the Command Line · With correctly set environment variables and ability to redirect output, you will find it much easier to run command-line programs (eg. BLAST) · To check where a program is installed, use · If the command is in your PATH, the shell will tell you where it is · Important to check when there is more than one version of the program installed (eg. Perl at GSC!) which Getting help Many programs will give short “help” messages when run without any parameters (eg. perl, blastall). Otherwise, try option –h or --help. To check the program version, try --version.

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Now you know…. · How to see and set permissions · How to customize your environment, and save customizations for future sessions · How to control input and output, and run a series of commands · Next you’ll learn…. · Job control · Command line goodies (really useful tools) · Command line Perl

– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Further Readings · Permissions · Linux Cookbook Ch. 7 · Learning the UNIX Operating System Ch. 3.3 · Customizing the shell · Linux Cookbook Ch. 4.6 · Learning the UNIX Operating System Ch. 3.6 · PS1: ibm.com/developerworks/linux/library/l-tip-prompt/ ibm.com/developerworks/linux/library/l-tip-prompt/ · Redirecting input and output · Linux Cookbook Ch. 4.2 · Learning the UNIX Operating System Ch. 5