Learning Linux Shell. Outline Introduction to Linux Learning the Shell Writing Shell Scripts.

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.
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.
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.
Linux+ Guide to Linux Certification, Second Edition
Information Networking Security and Assurance Lab National Chung Cheng University 1 What Linux is? Free Unix Like Open Source Network operating system.
UNIX Chapter 00 A “ Quick Start ” into UNIX Operating System Mr. Mohammad Smirat.
Lecture 01CS311 – Operating Systems 1 1 CS311 – Lecture 01 Outline Course introduction Setting up your system Logging onto the servers at OSU with ssh.
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.
Using Macs and Unix Nancy Griffeth January 6, 2014 Funding for this workshop was provided by the program “Computational Modeling and Analysis of Complex.
File Systems Sources and Resources: 1. A Students Guide to UNIX, by Hahn 2. Paula Davidson’s Handout on UNIXHandout on UNIX.
Overview of Linux CS3530 Spring 2014 Dr. José M. Garrido Department of Computer Science.
Help session: Unix basics Keith 9/9/2011. Login in Unix lab  User name: ug0xx Password: ece321 (initial)  The password will not be displayed on the.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
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.
Unix Basics Chapter 4.
CENT 305 Information Systems Security Linux Introduction.
Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Third Edition
Linux overview. Architecture Kernel File system Shell: Korn, Bourne, C, Bash X Windows: Motif, Open Look, X.OrgX.Org Desktop: Gnome, KDE,etc.
Carnegie Mellon Linux Boot Camp Jenna MacCarley, Peter Pearson, Shashank Goyal 9/19/2015.
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
Session 2 Wharton Summer Tech Camp Basic Unix. Agenda Cover basic UNIX commands and useful functions.
Week 3 Exploring Linux Filesystems. Objectives  Understand and navigate the Linux directory structure using relative and absolute pathnames  Describe.
1 Operating Systems and Using Linux Topics What is an Operating System? Linux Overview Frequently Used Linux Commands Some content in this lecture added.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
Chapter 1 : The Linux System Part 2 Lecture 2 11/14/
Week 8: Linux / ubuntu Dr. I. H. Shah. / CSCS 301 Fall 2009.
Introduction to Programming Using C An Introduction to Operating Systems.
Lesson 3-Touring Utilities and System Features. Overview Employing fundamental utilities. Linux terminal sessions. Managing input and output. Using special.
Linux Commands C151 Multi-User Operating Systems.
File Systems, telnet and ftp Sources and Resources: 1. A Students Guide to UNIX, by Hahn 2. Paula Davidson’s Handout on UNIXHandout on UNIX.
2 Manual & Filestore Mauro Jaskelioff. Introduction Using the manual The UNIX filestore File permissions.
CS 245 – Part 1 Using Operating Systems and Networks for Programmers Jiang Guo Dept. of Computer Science California State University Los Angeles.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
A gentle introduction to LINUX at the command prompt.
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.
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).
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.
Unix Lab Fall Shell Scripting ●Through the shell (LXTerminal) you can: ●Run programs. ●Interact with the file system. ●Change settings. ●Send/receive.
Learning Unix/Linux Based on slides from: Eric Bishop.
INTRODUCTION TO SHELL SCRIPTING By Byamukama Frank
UNIX  Portable (common to many computer architectures), multitasking, multi-user operating system  Introduced by Bell labs in mid-1960’s  Thus, much.
Overview of Linux Fall 2016 Dr. Donghyun Kim
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Tutorial of Unix Command & shell scriptS 5027
SUSE Linux Enterprise Desktop Administration
Commands Basic syntax of shell commands UNIX or shell commands have a basic structure command -options target command comes first (such as cd or ls) any.
Linux Commands Help HANDS ON TRAINING Author: Muhammad Laique
Andy Wang Object Oriented Programming in C++ COP 3330
Some Linux Commands.
The Linux Operating System
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
Web Programming Essentials:
Tutorial of Unix Command & shell scriptS 5027
Introduction Paul Flynn
Andy Wang Object Oriented Programming in C++ COP 3330
Command line.
Lab 2: Terminal Basics.
Presentation transcript:

Learning Linux Shell

Outline Introduction to Linux Learning the Shell Writing Shell Scripts

Unix A multitasking, multi-user computer operating system.

Linux Linux is a Unix-like OS. Linux is open source and free. Popular distributions (distros) are Ubuntu, Fedora/Red Hat, OpenSUSE, Mandriva, Mint, ArchLinux, Slackware… The mascot is a “slightly overweight Tux penguin”.

Benefits of UNIX/Linux Low cost and very stable (some Linux servers are not rebooted for over a year, try that with Windows server!). Best multi-user, multitasking OS. Most secure OS. Hence, it’s popularity as a server OS. Best computing power and inbuilt network support Fastest developing OS, with the most number of developers.

Learning the Shell What is “The Shell” Navigation Looking Around Text Editor Manipulating Files Help I/O Redirection Permissions Search

The Shell The Shell is a program used to interface between you and the Linux. The bash is the most popular and default shell. sh (Bourne shell) ssh (Secure shell) bash (Bourne Again shell) User Linux Shell Program Linux kernel

Features of bash Tab completion: the program automatically fills in partially typed commands Wild cards *: matches any character and any # of character. ?: matches any single character. […]: matches any single character content within the […]. ~]$ cat /proc/version Linux version el6.x86_64 (gcc version (Red Hat ) (GCC) ) #1 SMP Thu Aug 13 12:55:33 CDT 2015

A Terminal It's a program called a terminal emulator. This is a program that opens a window and lets you interact with the shell. Testing the keyboard Wonderful! Now press the up-arrow key. Watch how our previous command “blabla" returns. Yes, we have command history. Press the down-arrow and we get the most recent command. ~]$ blabla blabla: Command not found.

Learning the Shell What is “The Shell” Navigation Looking Around Text Editor Manipulating Files Help I/O Redirection Permissions Search

File System Organization

Three Commands pwd : print working directory. ls : list files and directories. cd : change directory.

pwd The directory you are standing in is called the working directory. To find the name of the working directory, use the pwd command. When you first log on to a Linux system, the working directory is set to your home directory (or your Desktop). ~]$ pwd /net/people/faculty/cs/yzhang

ls To list the files in the working directory, use the ls command. ~]$ ls bin Downloads mail Pictures research Trinity Desktop Music profile-bck rmi Videos Documents index.htm note.txt Public Templates www-docs

cd To change your working directory (where you are standing in the maze), type cd followed by the pathname of the desired working directory. The pathname of the directory is research, which is under your home directory. Notice how your prompt has changed? As a convenience, it is usually set up to display the name of the working directory. ~]$ cd Desktop Desktop]$ pwd /users/yzhang/Desktop

Two Kinds of Pathname An absolute pathname begins with the root directory “/” and leads to its destination. A relative pathname starts from the working directory. It uses three special notations to represent relative positions in the file system tree. The "." notation refers to the working directory itself. The ".." notation refers to the working directory's parent directory. The “~" notation refers to your home directory.

Desktop]$ cd.. ~]$ pwd /users/yzhang ~]$ cd./Desktop Desktop]$ pwd /users/yzhang/Desktop

Two Shortcuts If you type cd followed by nothing, cd will change the working directory to your home directory. If type cd ~user_name, cd will change the working directory to the home directory of the specified user. ~]$ cd Local/HTML-Documents/teaching/spring2016/ ]$ pwd /users/yzhang/Local/HTML-Documents/teaching/spring2016/ ]$ cd ~]$ pwd /users/yzhang ~]$ cd Desktop/ Desktop]$ cd ~]$ cd Desktop/ Desktop]$ cd ~yzhang ~]$ pwd /users/yzhang

Important Facts About File Names File names that begin with a period character (.) are hidden. File names are case sensitive. File.txt and file.txt refer to different files. Do not embed spaces in file names. If you want to represent spaces between words in a file name, use underscore characters. For example, this_is_a_file_of_linux_command.pdf.

Learning the Shell What is “The Shell” Navigation Looking Around Text Editor Manipulating Files Help I/O Redirection Permissions Search

Looking Around ls (list files and directories) less (view text files) file (classify a file's contents)

ls command -options ls –l  List the files in the working directory in l ong format. ls –la  List a ll files (including hidden files) in the working directory in long format. ~]$ ls –la ~]$ ls –l

-rw yzhang cs 50 Feb 24 09:21 a_test.txt drwx yzhang cs 4096 Dec bin -rw-r--r-- 1 yzhang cs 120 Feb 24 08:49 C:\nppdf32Log\debuglog.txt drwxr-xr-x 3 yzhang cs 4096 Feb 19 13:57 Desktop drwxr-xr-x 2 yzhang cs 4096 Aug 27 12:58 Documents drwxr-xr-x 2 yzhang cs Dec 10 12:54 Downloads drwx yzhang cs 4096 Jan 20 10:53 HiWorld File permissionsOwnerGroupSize (in bytes)Modification timeFile name

less less is a program that lets you view text files. This is very handy since many of the files used to control and configure Linux are human readable. You may use the Page Up and Page Down keys to move through the text file. To exit less, type " q ". ~]$ less a_test.txt This is a test file for the Linux "less" command. a_test.txt (END)

file file will examine a file and tell you what kind of file it is. 108 ~]$ file a_test.txt a_test.txt: ASCII English text

A Guided Tour cd into each directory. Use ls to list the contents of the directory. If you see an interesting file, use the file command to determine its contents. For text files, use less to view them.

Learning the Shell What is “The Shell” Navigation Looking Around Text Editor Manipulating Files Help I/O Redirection Permissions Search

vi Text Editor The default editor that comes with the UNIX operating system is called vi ( vi sual editor). Three modes of operation Command mode is the default when you enter vi. In command mode, everything that you type will be interpreted as commands.  Press Esc to return to command mode. In insert mode, whatever you type is inserted in the file at the cursor position.  Press Esc to return to command mode.  Type :a (lowercase letter a, for a ppend) to enter insert mode from command mode;  Press Esc to end insert mode, and return to command mode. Use line mode to enter line oriented commands.  In command mode, type a colon ( : ). Your cursor moves to the bottom of the screen, by a colon prompt.  Type a line mode command, then press Enter. See Manual: vi for a complete manual of vi.

Manipulating Files mkdir - create directories cp - copy files and directories mv - move or rename files and directories rm - remove files and directories

mkdir The mkdir command is used to create directories. Create a directory CSCI1320 in your home directory. ~]$ mkdir CSCI1320

Practice Read Practice: Linux Commands and do practices A1-8.

cp The cp program copies files and directories. Copy HelloWorld.scala to home directory. CSCI1320]$ cp HelloWorld.scala../.

mv The mv command moves or renames files and directories depending on how it is used. It will either move one or more files to a different directory, or it will rename a file or directory. Rename HelloWorld.scala to HowdyWorld.scala. CSCI1320]$ mv HelloWorld.scala HowdyWorld.scala

rm The rm command removes (deletes) files and directories. Remove HowdyWorld.java. CSCI1320]$ rm HowdyWorld.java

Practice (cont’d) Refer to Practice: Linux Commands and do the following two tasks: practices A9-15. On your own. Key concepts regards files and directories / root directory ~ home directory. current directory.. parent directory absolute path /dir/file vs. relative path../file

Learning the Shell What is “The Shell” Navigation Looking Around Text Editor Manipulating Files Help I/O Redirection Permissions Search

Help which - Display information about command type man - Display an on-line command reference  To exit man, type " q ". ~]$ which which alias which='alias | /usr/bin/which --tty- only --read-alias --show-dot --show-tilde' /usr/bin/which ~]$ which man /usr/bin/man

I/O Redirection We can redirect the output of many commands to files, devices, and even to the input of other commands. Standard Output By default, standard output directs its contents to the display. To redirect standard output to a file, the ">" character is used like this The scala command is executed and the result is written (redirected) in a file named output. So no result appear on the display. CSCI1320]$ scala HelloWorld.scala > output CSCI1320]$ less output Hello World!

I/O Redirection Standard Input By default, standard input gets its contents from the keyboard, but like standard output, it can be redirected. Download Redirect_Input_Output.scala from course website to your CSCI1320. Run it in terminal. Interact with the program by providing the input information. scala Redirect_Input_Output.scala Use vi to create a txt file called input. The content is: Run it again by these commands: Yu Zhang CSCI1320]$ scala Redirect_Input_Output output CSCI1320]$ less output What is your name? What is your phone number? Nice to meet you Yu Zhang. I will call you at

Learning the Shell What is “The Shell” Navigation Looking Around Text Editor Manipulating Files Help I/O Redirection Permissions Search

Permissions CSCI1320]$ ls -l /bin/bash -rwxr-xr-x 1 root root Jul 22 09:12 /bin/bash

Permissions chmod - modify file access rights. It is easy to think of the permission settings as a series of bits (which is how the computer thinks about them). Here's how it works: rwx rwx rwx = rw- rw- rw- = rwx = and so on... rwx = 111 in binary = 7 rw- = 110 in binary = 6 r-x = 101 in binary = 5 r-- = 100 in binary = 4

Permissions CSCI1320]$ chmod 600 some_file Now, if you represent each of the three sets of permissions (owner, group, and other) as a single digit, you have a pretty convenient way of expressing the possible permissions settings. For example, if we wanted to set some_file to have read and write permission for the owner, but wanted to keep the file private from others, we would:

Permissions

Learning the Shell What is “The Shell” Navigation Looking Around Text Editor Manipulating Files Help I/O Redirection Permissions Search

The grep command is used to search text or searches the given file for lines containing a match to the given strings or words. By default, grep displays the matching lines. Use grep to search for lines of text that match one or many regular expressions, and outputs only the matching lines. grep is considered as one of the most useful commands on Linux. grep 'word' filename grep 'word' file1 file2 file3 grep 'string1 string2' filename grep --color 'data' fileName

Search Download file_for_grep.txt from the course website to your CSCI1320. You can force grep to ignore word case i.e match abc, ABC and all other combination with the -i option: CSCI1320]$ grep abc file_for_grep.txt abcdefg CSCI1320]$ grep -i abc file_for_grep.txt abcdefg ABCDEFG

Search You can search recursively i.e. read all files under each directory for a string “abc“, with the -r option. Or combine options –r and –i. Use grep to search words only with the -w option. CSCI1320]$ cd ~]$ grep -r abc CSCI1320 CSCI1320/file_for_grep.txt:abcdefg ~]$ grep -ri abc CSCI1320 CSCI1320/file_for_grep.txt:abcdefg CSCI1320/file_for_grep.txt:ABCDEFG ~]$ grep -riw Inauguration CSCI1320 1Linux/file_for_grep.txt:The Inauguration of Trinity's 19th president, Danny Anderson, is just a 1Linux/file_for_grep.txt:little more than a month away now. The Inauguration Committee and other 1Linux/file_for_grep.txt:participate in all the Inauguration events starting with the Day of 1Linux/file_for_grep.txt:Inauguration will be a great way to show your TigerPride.

Search Use grep to search 2 different words. Use the -l option to list file name whose contents mention “college”: you can force grep to display output in colors ~]$ grep -riw 'Danny Anderson' CSCI1320 1Linux/file_for_grep.txt:The Inauguration of Trinity's 19th president, Danny Anderson, is just a ~]$ grep -rl Trinity CSCI1320 CSCI1320/file_for_grep.txt ~]$ grep -r --color Trinity CSCI1320 1Linux/file_for_grep.txt:The Inauguration of Trinity's 19th president, Danny Anderson, is just a 1Linux/file_for_grep.txt:celebrate this important moment in Trinity's history. I hope you plan to 1Linux/file_for_grep.txt:Service as "Trinity Gives Back" on Feb. 13. The "Great Trinity 1Linux/file_for_grep.txt:our classrooms. On Friday, Feb. 19, plan to wear your Trinity maroon and