1 CSE 303 Lecture 3 bash shell continued: processes; multi-user systems; combining commands read Linux Pocket Guide pp. 25-33, 104-107, 111-113, 118, 122,

Slides:



Advertisements
Similar presentations
RH030 Linux Computing Essentials
Advertisements

Linux commands exercise 1. What do you need, if you try to these at home? You need to download and install Ubuntu Linux from the Internet – DVD is need.
Learning Unix/Linux Bioinformatics Orientation 2008 Eric Bishop.
Introduction to Unix – CS 21 Lecture 10. Lecture Overview Midterm questions Jobs and processes description The foreground and background Controlling jobs.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Cosc 4750 Getting Started in UNIX Don’t be afraid of the prompt, in linux it can be your best friend. In some cases, the only way to do certain things.
David Notkin Autumn 2009 CSE303 Lecture 3 Dictionary.com, “shell," in Dictionary.com Unabridged. Source location: Random House, Inc.
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 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Josh Goodwin
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.
CSE 303 Lecture 2 Introduction to bash shell
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Introduction to Linux Workshop February Introduction Rob Lane & The HPC Support Team Research Computing Services CUIT.
Introducing UNIX EMBnet slide 1 Introducing the UNIX Operating System.
CSE 390a Editing and Moving Files
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
Lesson 1. PC vs. Multi-user System  Personal Computer – each user gets his/her own processor (or multicore processor).  Multi-user system – The processor,
UNIX command line. In this module you will learn: What is the computer shell What is the command line interface What is the directory tree Some UNIX commands.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
PROGRAMMING PROJECT POLICIES AND UNIX INTRO Sal LaMarca CSCI 1302, Fall 2009.
Next Unix Topics Tuesday, 2/11 & 18/2014. Change Password (by 2/14/14) ssh to account on – faclinux.cse.ohio-state.edu – stdlinux.cse.ohio-state.edu passwd.
1 CSE 303 Lecture 5 bash continued: users/groups; permissions; intro to scripting read Linux Pocket Guide pp slides created by Marty Stepp
Chapter Four I/O Redirection1 System Programming Shell Operators.
Week 9 - Nov 7, Week 9 Agenda I/O redirection I/O redirection pipe pipe tee tee.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
CSE 374 Programming Concepts & Tools Hal Perkins Fall 2015 Lecture 2a – A Unix Command Sampler (Courtesy of David Notkin, CSE 303)
Linux Commands C151 Multi-User Operating Systems.
 Last lesson, the Windows Operating System was discussed along with the Windows command shell  Unix is a computer operating system, that similarly manages.
Agenda The Bourne Shell – Part I Redirection ( >, >>,
1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Jessica Miller & Ruth Anderson
1 CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
Learning Unix/Linux Based on slides from: Eric Bishop.
Assignprelim.1 Assignment Preliminaries © 2012 B. Wilkinson/Clayton Ferner. Modification date: Jan 16a, 2014.
Exploring Shell Commands, Streams, and Redirection
slides created by Marty Stepp, modified by Josh Goodwin
CSE 391 Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
CSE 391 Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
Some Linux Commands.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands:
Exploring Shell Commands, Streams, and Redirection
CSE 374 Programming Concepts & Tools
CSE 303 Concepts and Tools for Software Development
Exploring Shell Commands, Streams, and Redirection
Introduction to UNIX.
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
CSE 391 Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
slides created by Marty Stepp, modified by Jessica Miller
Multi-user systems; remote login; editors; users/groups; permissions
Exploring Shell Commands, Streams, and Redirection
CSE 391 Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, Redirection, and Processes
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
Linux Shell Script Programming
slides created by Marty Stepp, modified by Jessica Miller
CSE 391 Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
CSE 303 Concepts and Tools for Software Development
CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
CSE 390a Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
CSE 391 Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, and Redirection
CSE 391 Lecture 3 bash shell continued: processes; multi-user systems; remote login; editors slides created by Marty Stepp, modified by Jessica Miller.
Presentation transcript:

1 CSE 303 Lecture 3 bash shell continued: processes; multi-user systems; combining commands read Linux Pocket Guide pp , , , 118, 122, , 138 slides created by Marty Stepp

2 Lecture summary processes and basic process management connecting to remote servers ( attu )  multi-user environments combining commands  input/output redirection  pipes

3 Processes

4 Process commands process: a program that is running (essentially)  when you run commands in a shell, it launches processes for each use kill or killall to stop a runaway process (infinite loop)  similar to ^C hotkey, but doesn't require keyboard intervention commanddescription ps or jobs list processes being run by a user; each process has a unique integer id (PID) top show which processes are using CPU/memory; also shows stats about the computer kill terminate a process by PID killall terminate several processes by name

5 Background processes If you run a graphical program like gedit from the shell, the shell will lock up waiting for the graphical program to finish  instead, run the program in the background, so the shell won't wait: $ gedit resume.txt &  if you forget to use &, suspend gedit with ^Z, then run bg commanddescription & (special character) when placed at the end of a command, runs that command in the background ^Z (hotkey) suspends the currently running process fg, bg resumes the currently suspended process in either the foreground or background

6 Connecting with ssh Linux/Unix are built to be used in multi-user environments where several users are logged in to the same machine at the same time  users can be logged in either locally or via the network You can connect to other Linux/Unix servers with ssh  once connected, you can run commands on the remote server  other users might also be connected; you can interact with them commanddescription ssh open a shell on a remote server

7 The attu server attu : The UW CSE department's shared Linux server connect to attu by typing: ssh attu.cs.washington.edu (or ssh if your Linux system's user name is different than your CSE user name) attu uses a shell other than bash as its default, so the first time you ever log in to it, you must run chsh to change shell to bash  when prompted for a new shell, type: /bin/bash Note: There are several computers that respond as attu (to spread load), so if you want to be on the same machine as your friend, you may need to connect to attu2, attu3, etc.

8 Multi-user environments Linux/Unix are built to be used in a multi-user environment where several users are logged in to the same machine at the same time  users can be logged in either locally or via the network Exercise : Connect to attu, and send somebody else a message. commanddescription whoami outputs your username passwd changes your password hostname outputs this computer's name/address w or finger see info about people logged in to this server write send a message to another logged in user

9 Network commands commanddescription links or lynx text-only web browsers (really!) ssh connect to a remote server sftp or scp transfer files to/from a remote server wget download from a URL to a file curl download from a URL and output to console pine, mail text-only programs

10 Text editors you cannot run graphical programs when connected to attu (yet)  so if you want to edit documents, you need to use a text-only editor most advanced Unix/Linux users learn emacs or vi  these editors are powerful but complicated and hard to learn  we recommend the simpler pico (hotkeys are shown on screen) commanddescription pico or nano simple but crappy text editors (recommended) emacs complicated text editor vi or vim complicated text editor

11 Output redirection command > filename  run command and write its output to filename instead of to console; think of it like an arrow going from the command to the file... if the file already exists, it will be overwritten (be careful) >> appends rather than overwriting, if the file already exists command > /dev/null suppresses the output of the command  Example: ls -l > myfiles.txt  Example: java Foo >> Foo_output.txt  Example: cat > somefile.txt (writes console input to the file until you press ^D )

12 Input redirection command < filename  run command and read its input from filename instead of console whenever the program prompts the user to enter input (such as reading from a Scanner in Java), it will instead read the input from a file some commands don't use this; they accept a file name as an argument  Example: java Guess < input.txt  Example: write stepp < insult.txt  Example: java Guess output.txt  note that this affects user input, not parameters  useful with commands that can process standard input or files: e.g. grep, more, head, tail, wc, sort, uniq, write

13 Combining commands command1 | command2  run command1 and send its console output as input to command2  very similar to the following sequence: command1 > filename command2 < filename rm filename  Examples: grep secret *.txt | uniq ls -l *.txt | more  Exercise : names.txt contains CSE student names, one per line, in "LASTNAME, FIRSTNAME" format. We are interested in students whose first names begin with "J", such as "Sherry, Justine". Find out of how many such students are in the file. Then figure out how many total letters (including comma and spaces) are in the full name of the last student in alphabetical order from this group.

14 Misusing pipes and cat Why doesn't this work to compile all Java programs? ls *.java | javac Misuse of cat  bad: cat filename | command  good: command < filename  bad: cat filename | more  good: more filename  bad: command | cat  good: command

15 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

16 Exercise The file byebye.txt contains a list of students who got < 2.0 in CSE 143, one per line, in sorted order by name.  Some names occur more than once, because they retook the course. Run the Java Reject program located in Reject.class, which s rejection letters to these students.  The program reads the student names from the console; give the program the student names from byebye.txt as its input.  The Reject program should process each student only once, since it would be rude to send one person two rejection letters.  Once you get this to work, make it save the list of people sent rejection letters to the file rejected.txt.