CSE 303 Lecture 2 Introduction to bash shell

Slides:



Advertisements
Similar presentations
David Notkin Autumn 2009 CSE303 Lecture 2 Dictionary.com, "bash," in Dictionary.com Unabridged. Source location: Random House, Inc.
Advertisements

NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
1 CSE 390a Lecture 1 introduction to Linux/Unix environment slides created by Marty Stepp, modified by Josh Goodwin
1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Josh Goodwin
Guide To UNIX Using Linux Third Edition
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
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
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
INTRODUCTION TO LINUX Jacob Chan. GNU/Linux Consists of Linux kernel, GNU utilities, and open source and commercial applications Works like Unix –Multi-user.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
Introduction to UNIX Road Map: 1. UNIX Structure 2. Components of UNIX 3. Process Structure 4. Shell & Utility Programs 5. Using Files & Directories 6.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: whereis, which, whoami, finger, passwd, cal, date Working with Files: cat, more, less.
1 CSE 390a Lecture 1 introduction to Linux/Unix environment slides created by Marty Stepp, modified by Jessica Miller & Ruth Anderson
1 CSE 390a Lecture 1 introduction to Linux/Unix environment slides created by Marty Stepp, modified by Jessica Miller & Ruth Anderson
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
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.
UNIX filesystem CS 2204 Class meeting 2 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
1 CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection slides created by Marty Stepp, modified by Jessica Miller & Ruth Anderson
introduction to Linux/Unix environment
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
Learning Unix/Linux Based on slides from: Eric Bishop.
Exploring Shell Commands, Streams, and Redirection
introduction to Linux/Unix environment
introduction to Linux/Unix environment
introduction to Linux/Unix environment
introduction to Linux/Unix environment
Some Linux Commands.
C151 Multi-User Operating Systems
introduction to Linux/Unix environment
The Command Prompt Commands are the way to “do things” in Unix
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands:
Exploring Shell Commands, Streams, and Redirection
CSE 374 Programming Concepts & Tools
introduction to Linux/Unix environment
Exploring Shell Commands, Streams, and Redirection
Introduction to UNIX.
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
Introduction to Linux Week 0 - Thursday.
CSE 390a Lecture 1 introduction to Linux/Unix environment
Exploring Shell Commands, Streams, and Redirection
The Unix File System.
Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, and Redirection
CSE 390a Lecture 1 introduction to Linux/Unix environment
introduction to Linux/Unix environment
introduction to Linux/Unix environment
Exploring Shell Commands, Streams, Redirection, and Processes
CSE 390a Lecture 2 Exploring Shell Commands, Streams, and Redirection
introduction to Linux/Unix environment
Linux Shell Script Programming
introduction to Linux/Unix environment
introduction to Linux/Unix environment
Module 6 Working with Files and Directories
introduction to Linux/Unix environment
introduction to Linux/Unix environment
introduction to Linux/Unix environment
Exploring Shell Commands, Streams, and Redirection
Exploring Shell Commands, Streams, and Redirection
A shell is a user interface.
Exploring Shell Commands, Streams, and Redirection
January 26th, 2004 Class Meeting 2
introduction to Linux/Unix environment
Exploring Shell Commands, Streams, and Redirection
Presentation transcript:

CSE 303 Lecture 2 Introduction to bash shell read Linux Pocket Guide pp. 37-46, 58-59, 60, 65-70, 71-72, 77-80 slides created by Marty Stepp http://www.cs.washington.edu/303/

Lecture summary Unix file system structure basic shell commands commands for file manipulation, examination, searching keyboard shortcuts and special characters

Unix file system directory description / root directory that contains all others (drives do not have letters in Unix) /bin programs /dev hardware devices /etc system configuration files /etc/passwd stores user info /etc/shadow stores passwords /home users' home directories /media, /mnt, ... drives and removable disks that have been "mounted" for use on this computer /proc currently running processes (programs) /tmp, /var temporary files /usr user-installed programs

Relative directories directory description . the directory you are in ("working directory") .. the parent of the working directory (../.. is grandparent, etc.) ~ your home directory (on many systems, this is /home/username ) ~username username's home directory ~/Desktop your desktop

Shell commands many accept arguments or parameters example: cp (copy) accepts a source and destination file path a program uses 3 streams of information: stdin, stdio, stdout (standard in, out, error) input: comes from user's keyboard output: goes to console errors can also be printed (by default, sent to console like output) parameters vs. input parameters: before Enter is pressed; sent in by shell input: after Enter is pressed; sent in by user

Directory commands some commands (cd, exit) are part of the shell ("builtins") others (ls, mkdir) are separate programs the shell runs command description ls list files in a directory pwd output the current working directory cd change the working directory mkdir create a new directory rmdir delete a directory (must be empty)

Command-line arguments most options are a - followed by a letter such as -c some are longer words preceded by two - signs, such as --count parameters can be combined: ls -l -a -r can be ls -lar many programs accept a --help or -help parameter to give more information about that command (in addition to man pages) or if you run the program with no arguments, it may print help info for many commands that accept a file name parameter, if you omit the parameter, it will read from standard input (your keyboard) note that this can conflict with the previous tip

Shell/system commands "man pages" are a very important way to learn new commands man ls man man command description man or info get help on a command clear clears out the output from the console exit exits and logs out of the shell command description date, time output the system date/time cal output a text calendar uname print information about the current system

File commands caution: the above commands do not prompt for confirmation easy to overwrite/delete a file; this setting can be overridden (how?) Exercise : Given several albums of .mp3 files all in one folder, move them into separate folders by artist. Exercise : Modify HW4.java to make it seem as though you finished writing it on March 15 at 4:56am. command description cp copy a file mv move or rename a file rm delete a file touch create a new empty file, or update its last-modified time stamp

File examination Suppose you are writing a paper, and the teacher says it can be anything as long as it is at least 200 words long and mentions 303... command description cat output a file's contents on the console more or less output a file's contents, one page at a time head, tail output the first or last few lines of a file wc count words, characters, and lines in a file du report disk space used by a file(s) diff compare two files and report differences

Searching and sorting grep is actually a very powerful search tool; more later... Exercise : Given a text file students.txt, display the students arranged by the reverse alphabetical order of their last names. Can we display them sorted by first name? command description grep search a file for a given string sort convert an input into a sorted output by lines uniq strip duplicate lines find search for files within a given directory locate search for files on the entire system which shows the complete path of a command

Programming Exercise : Write/compile/run a program that prints "Hello, world!" $ javac Hello.java $ java Hello Hello, world! $ command description javac ClassName.java compile a Java program java ClassName run a Java program python, perl, ruby, gcc, sml, ... compile or run programs in various other languages

^KEY means hold Ctrl and press KEY Keyboard shortcuts ^KEY means hold Ctrl and press KEY key description Up arrow repeat previous commands Home/End or ^A/^E move to start/end of current line " quotes surround multi-word arguments and arguments containing special characters * "wildcard" , matches any files; can be used as a prefix, suffix, or partial name Tab auto-completes a partially typed file/command name ^C or ^\ terminates the currently running process ^D end of input; used when a program is reading input from your keyboard and you are finished typing ^Z suspends (pauses) the currently running process ^S don't use this; hides all output until ^G is pressed

Links hard link: Two names for the same file. command description ln create a link to a file unlink remove a link to a file hard link: Two names for the same file. $ ln foo bar the above command links bar as a duplicate name for foo if one is modified, the other is too; if one is deleted, both will go away soft (symbolic) link: A reference to another existing file. $ ln -s foo bar the above command creates a reference bar to the file foo bar can be used as though it were foo but if bar is deleted, foo will be unaffected