Shell - Introduction & Commands Chapter III / Part II.

Slides:



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

CIS 118 – Intro to UNIX Shells 1. 2 What is a shell? Bourne shell – Developed by Steve Bourne at AT&T Korn shell – Developed by David Korn at AT&T C-shell.
A Practical Guide to Fedora and Red Hat Enterprise Linux Unit 4: More Command Line Interface (CLI) Chapter 7: The Linux Shell By Fred R. McClurg Linux.
Unix. Outline Commands Environment Variables Basic Commands CommandMeaning lslist files and directories ls -alist all files and directories mkdirmake.
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.
Exploring the UNIX File System and File Security
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.
Linux+ Guide to Linux Certification, Second Edition
The UNIX File System.
Guide To UNIX Using Linux Third Edition
Guide To UNIX Using Linux Third Edition
1 UNIX essentials (hands-on) the directory tree running programs the shell (using the T-shell) → command line processing → special characters → command.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
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.
Using the “CLI” Unix / Linux Preparation Course May 25 Djibouti.
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 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.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
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
Unix Basics Chapter 4.
Basic unix commands that everyone should know (Even if you have a mac) Slightly more advanced:
Introduction to Unix – CS 21 Lecture 9. Lecture Overview Shell description Shell choices History Aliases Topic review.
The Shell Chapter 7. Overview The Command Line Standard IO Redirection Pipes Running a Program in the Background Killing (a process!)
1 UNIX essentials (hands-on) the directory tree running programs the shell → command line processing → special characters → command types → shell variables.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Chapter Two Exploring the UNIX File System and File Security.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
INTRODUCTION TO LINUX Jacob Chan. GNU/Linux Consists of Linux kernel, GNU utilities, and open source and commercial applications Works like Unix –Multi-user.
UNIX/LINUX Shells Shell is an UNIX/LINUX command interpreter. Shell command can be internal or external. The code to execute an internal command is part.
Guide to Linux Installation and Administration, 2e1 Chapter 7 The Role of the System Administrator.
1 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Some content in this lecture added.
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.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
Chapter Two Exploring the UNIX File System and File Security.
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.
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.
CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Lecture 02 File and File system. Topics Describe the layout of a Linux file system Display and set paths Describe the most important files, including.
A Brief Overview of Unix Brandon Bohrer. Topics What is Unix? – Quick introduction Documentation – Where to get it, how to use it Text Editors – Know.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
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.
Operating Systems and Using Linux Courtesy of John Y. Park 1.
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Learning Unix/Linux Based on slides from: Eric Bishop.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Some Linux Commands.
C151 Multi-User Operating Systems
The Linux Operating System
CSE 374 Programming Concepts & Tools
Basic UNIX OLC Training.
Introduction to UNIX.
Exploring the UNIX File System and File Security
Unix : Introduction and Commands
Shells, Help, and Paths.
Linux Shell Script Programming
CSE 303 Concepts and Tools for Software Development
Chapter 3 The UNIX Shells
A shell is a user interface.
Presentation transcript:

Shell - Introduction & Commands Chapter III / Part II

Command Line Interface Earlier - only command line interface (CLI) Inheritance from Unix, just like other OS of that time CLI poses steep learning curve for some Unintuitive Needed to be terse for brevity and other reasons Necessary to do many tasks Convenient for other complex tasks Much more tedious by GUI For eg., delete all.avi files in current directory rm *.avi

Shells Interprets and executes commands different shells are installed by default Each shell has slightly different environment & features Examples bash - most common, powerful csh - C shell, less features than bash sh - Bourne shell, oldest zsh - new, quite powerful to find out the particular shell type echo $SHELL should return something like /bin/bash cat /etc/shells to change shell use the command chsh

Shells (contd.) Some useful key commands Ctrl - U : delete the whole typed line Ctrl - C : abort a running command Ctrl - Z : suspend a running command stty -a gives a list of terminal settings Terminal emulators GUI window lets you interact with a shell Just a container for the shell gnome-terminal is GNOME’s most used emulator KDE uses konsole No emulator needed if logging on to terminal directly Start a terminal (without X) by using CTR-Alt-F1 to Ctrl-Alt-F8 Ctrl-Alt-F7 is X (the GUI)

Common commands: Navigating directories Linux (as Windows) has hierarchical directory structure Each component is seperated by forward slash - / ‘/’ is the root directory Examples /usr/bin/ /home/raheel To find out the current directory: pwd - returns the current directory To change to another directory: cd /path/to/dir. is the current directory.. is the parent directory

Paths define the location of a file or directory seperated by slashes: / Could be absolute or relative Absolute starts with the root directory /home/raheel/paper.txt, /usr/local/bin Relative in relation to the current directory pwd -> /home/raheel, cd hw -> /home/raheel/hw cd.. -> /home/raheel

Important directories /bin : essential Unix commands, like ls /usr/bin : some extra Unix commands /usr/sbin : for super user, system administration /boot : kernel and other files for booting /etc : system services - networking, mail, disk management /var : administrative files, such as logs /usr/local : locally added programs and files by sys. admin. /dev : device files - interface b/w hardware and filesystem /proc : running processes

Navigating directories (contd.) cd by itself - takes to home directory cd ~ also Home directory also denoted by ‘~’ cd. doesn’t do anything cd.. takes you to parent directory To make a directory: mkdir dirname creates new directory under current one mkdir /path/to/dirname creates new directory under the exact path rmdir removes a directory

Listing files ls - the most popular command lists the directory contents lots of options available with arguments argument - option given to a command ls lists current directory’s contents ls /home lists the contents of /home directory ls -a list hidden files with the -a argument ls -l ‘long’ information about contents. Very useful

What is a command? Small (big) program provided by UNIX/Linux Can make your own commands too Command is simply a file Have to mark it executable Put it somewhere special (in command path) Path : directories where shell looks for a given command find out Path by echo $PATH /usr/local/bin/:/usr/bin:/bin/ Sometime have to specify full (absolute path) to a command not in path more than one name for same command

Command (contd.) Add a directory to path export PATH=$PATH:/new/directory/path current directory usually not in path use./command-name Help for commands man command-name man 2 command-name : for 2nd section apropos edit : displays all commands related to editing Put a command in background ls & -> [1] Bring it back fg %1 or fg Commands and shell provided features type ls type cd

Typing shortcuts Word Completions Don’t have to type full command or path Type Tab after typing a couple of letters cd /usr/inc - then hit Tab would complete it as cd /usr/include/ completes the path Works on commands too Type mor and then hit Tab Will complete it as the command more If more than one match, the displays the options Type cd /usr/l and hit Tab Would display lib and local because they begin with l

Command line editing Can edit previously typed commands Commands are stored once typed No. of commands to be stored in history can be set Can recall previous commands and use them Up arrow - previous command Down arrow - next command Left and right arrow to navigate Ctrl-U to delete whole line if mistyped Ctrl-A : beginning of line Ctrl-E : end of line

Command history in detail! Can view previous commands in one display type history displays history of commands, numbered history N displays only N previous commands history -c deletes all commands in history !! execute previous command !N execute the Nth command from top

Exapnding filenames (wildcards) Specify a group of files/directories with a single word if ls gives paper1.doc paper2.doc paper3.doc papa.doe prayer.doc thesis.doc work.ppt Then ls *.doc will give paper1.doc paper2.doc paper3.doc prayer.doc thesis.doc * says ‘match as many characters as possible in place of *’ ? says ‘match one character in place of ?’ ls paper?.doc gives paper1.doc paper2.doc paper3.doc

More wildcards Can use * in between a word ls p*.doc will give paper1.doc paper2.doc paper3.doc Can specify characters instead of ? and * ls paper[123].doc will give paper1.doc paper2.doc paper3.doc ls paper[2-3].doc will give paper2.doc paper3.doc Can combine wildcards ls pap*.do? will give paper1.doc paper2.doc paper3.doc papa.doe

Startup files Customize environment before starting the shell Default startup file: /etc/profile Interactive and non-interactive shell sessions Interactive: where user can enter commands for that session login; same as bash --login; uses.bash_profile non-login: changing users, by bash, uses.bashrc Non-interactive: started by other processes, no user control Can contain commands and programs comment: #this is a comment line PS1 = \u HISTSIZE = 50 path definition: PATH=/usr/local/bin:/bin:/usr/bin rename commands: alias rm=rm -i

Some file management commands touch filename - create an empty file Copying files cp /file/to/copy /where/to/copy cp -r /dir/to/copy /where/to/copy Moving files mv /original/file/location /new/file/location Deleting files rm /file/to/remove rm -r /dir/to/remove rm -f /file/to/remove

Processes Core concept of Linux Independent running programs, responsible for different tasks Can communicate between each other ls | more To view processes ps : view personal processes ps -a : view processes from all users ps -aux : view all processes including those with no terminal last command sorts by CPU usage more or less

Killing processes If can’t kill a process by Ctrl-c use kill command ps -aux shows all running commands Note PID for the process kill PID kill -9 PID : un-ignorable kill -STOP PID kill -CONT PID need to be root to kill other’s processes

Input to a command could be from anywhere keyboard - default standard input (stdin) file another process’ output Output from a command could go anywhere monitor - default standard output (stdout) file another process’ input Also, standard error (stderr) - all errors go here by default - monitor display Standard Input / Output

Output redirection To redirect stdout from a command use ‘>’ ls -l /etc/ > listing.txt redirects the output from ls command to the file listing.txt cat file2 displays file2’s content on display cat file2 > file2_copy copies the content to file2_copy (using redirection) If file2 doesn’t exist, above generates error cat: file3: No such file or directory Redirect error using ‘2>’ cat file2 2> file_error.txt To redirect both stdout and stderr cat file2 > file2_copy 2>file_error.txt copies standard output to file2_copy and error to error.txt cat file2 > file2_copy 2>&1 copies either error or standard output to file2_copy

Input Redirection Works similar to output redirection Can read from file or another command sort command by itself gives sorts lines typed on the command line sort < listing.txt sorts the lines stored in listing.txt Can combine output and input sort < listing.txt > sorted_listing.txt Word count wc < listing.txt counts lines, words, bytes in listing.txt

More stdin/stdout To redirect output to nothing: use /dev/null - special file, size always 0. doesn’t retain anything cat listing.txt > /dev/null : gets rid of output To redirect to printer sort < listing.txt > /dev/lp0 To append to a file cat file2 > file3 erases contents of file3 cat file2 >> file3 appends to file3 cat >> file3 appends whatever is typed to file3

Pipes Connect standard output of a command to standard input of another channel output to input Can be done using redirection To count number of files in /etc ls /etc > output.txt wc output.txt Two lines needed, a temporary file created Better to use pipes ls /etc | wc - same result as above

More Pipes Most powerful feature of shell Gives great flexibility to perform complex tasks simply Commands can be modular and simple functioning It is this combination of commands that give power to Linux Print a list of current users on the computer who | lpr View the output of a listing one screen at a time ls /etc | less Mostly used with filters

Filters Small utility commands Take input from stdin Do some operation Post output to stdout Example cat grep - search text sort - according to some criteria head - display first few lines of text tail - display last few lines of text Very useful when combined with other commands using pipes

Filters in action Search files in /etc containing ‘pe’ in their names ls /etc/ | grep pe Printing the above files ls /etc/ | grep pe | lpr View the first few files in listing for /etc ls /etc/ | head Total statistics of file1, file2, file3 cat file1 file2 file3 | wc View all files in /etc/ last modified in January ls -l | grep "Aug"