LIN 69321 Unix Lecture 3 Hana Filip. LIN 69322 UNIX Resources UNIX Tutorials UNIX help for.

Slides:



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

Jump to first page Unix Commands Monica Stoica Jump to first page Introduction to Unix n Unix was born in 1969 at Bell Laboratories, a research subdivision.
NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Lab6 CPCS361 I.Mona Alshehri. Working with Files and Directories Creating files Create a file with the cat command type the command cat > name_of_file.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Jan. 27 th, 2009 Essential Unix Commands.
Linux+ Guide to Linux Certification, Second Edition
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Using Linux Commands Lab 4. Using the Shell in Linux Commands Syntax  Options: could be added to the commands to change their behavior (-a, -la, --help)
LIN Unix Lecture 4 Hana Filip. LIN File Management with Shell Commands The verbose listing shows the file permissions of a given file: -rwxr-xr-x.
Shell Script Examples.
7/17/2009 rwjBROOKDALE COMMUNITY COLLEGE1 Unix Comp-145 C HAPTER 2.
Linux Commands LINUX COMMANDS.
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.
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”
Lesson 7-Creating and Changing Directories. Overview Using directories to create order. Managing files in directories. Using pathnames to manage files.
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 Directory Navigation. File & Directory Commands This is a minimal list of Unix commands that you must know for file management: ls (list) mkdir.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
Basic unix commands that everyone should know (Even if you have a mac) Slightly more advanced:
Linux+ Guide to Linux Certification, Second Edition
Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems.
Linux+ Guide to Linux Certification, Third Edition
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.
Scripting Languages Course 2 Diana Trandab ă ț Master in Computational Linguistics - 1 st year
Lesson 9-Setting and Using Permissions. Overview Describing file permissions. Using execute permissions with a file. Changing file permissions using mnemonics.
1 Operating Systems Lecture 2 UNIX and Shell Scripts.
Lesson 2-Touring Essential Programs. Overview Development of UNIX and Linux. Commands to execute utilities. Communicating instructions to the shell. Navigating.
Second edition Your UNIX: The Ultimate Guide Das © 2006 The McGraw-Hill Companies, Inc. All rights reserved. UNIX Commands cal – will print a calendar.
BIF713 Basic Unix/Linux Commands Getting Help with Commands.
UNIX An Introduction. Brief History UNIX UNIX Created at Bell Labs, 1969 Created at Bell Labs, 1969 BSD during mid 70s BSD during mid 70s AT&T began offering.
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: whereis, which, whoami, finger, passwd, cal, date Working with Files: cat, more, less.
Linux+ Guide to Linux Certification, Third Edition
LIN Unix Lecture 5 Unix Shell Scripts. LIN Command Coordination ; && || command1 ; command2 Interpretation: Do command 1. Then do command.
Using Linux Commands Lab 4. Using the Shell in Linux Commands Syntax  Options: could be added to the commands to change their behavior (-a, -la, --help)
Λειτουργικά Συστήματα – Lab2 Γιάννης Πετράκης. Directory Navigation and Control  The Unix file system is set up like a tree branching out from the root.
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.
2 Manual & Filestore Mauro Jaskelioff. Introduction Using the manual The UNIX filestore File permissions.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
1 Introduction to Unix. 2 What is UNIX?  UNIX is an Operating System (OS).  An operating system is a control program that helps the user communicate.
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.
Unix Fundamentals CS 127. File navigation cd - change directory cd /var/log cd /etc/apache2 cd ~/Desktop ~ is a shortcut for the home directory.
Learning basic Unix command It 325 operating system.
Lesson 6-Using Utilities to Accomplish Complex Tasks.
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.
Learning Unix/Linux Based on slides from: Eric Bishop.
Login Being logged into a command line prompt allows a user to easily and simply execute multiple commands (one-by-one or at the same time) that would.
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
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.
Prepared by: Eng. Maryam Adel Abdel-Hady
Lecture 2 Working with Files and Directories
Some Linux Commands.
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Tutorial of Unix Command & shell scriptS 5027
Using Linux Commands Lab 3.
Tutorial of Unix Command & shell scriptS 5027
Introduction Paul Flynn
Tutorial Unix Command & Makefile CIS 5027
Linux Commands LINUX COMMANDS.
January 26th, 2004 Class Meeting 2
Presentation transcript:

LIN Unix Lecture 3 Hana Filip

LIN UNIX Resources UNIX Tutorials UNIX help for Users (developed at the University of Edinburgh) “Grep for Linguists” (by Stuart Robinson):

LIN Overview File Management with Shell Commands Simple Script Grep and Egrep

LIN File Management with Shell Commands How to name a file –File = a collection of characters –The name must be all one ‘word’ or ‘string of characters’ –No spaces are allowed, because spaces are used by UNIX (and other operating systems) to identify the discrete ‘pieces’ of a command line in the same way they are used in regular expressions –14 characters or less (less is better)

LIN File Management with Shell Commands % vi letter to mom “edit three separate files named letter, to and mom”

LIN File Management with Shell Commands Don’t begin a file with a character that is not a letter or number NEVER use the characters ! “ * > < | ?

LIN File Management with Shell Commands ACCEPTABLE NOT ACCEPTABLE ozzieozzie nelson why-mewhy-me? bonzo-4bonzo 4 English190Enlgish 190 greatgreat! prog1*prog1 fido.nerfball fido nerfball

LIN File Management with Shell Commands % script [RETURN] % who % date % whoami % [CTRL-D] % exit Script done, output file is typescript

LIN File Management with Shell Commands To see what’s in your typescript file: % more typescript or (depending on the UNIX version) % page typescript 1. To see the next screenful of text press the SPACEBAR 2. If you wish to return to the Shell, press the DELETE key % less typescript % cat typescript

LIN File Management with Shell Commands To see what’s in your typescript file: % head typescript displays the first 10 lines of a file % tail typescript displays the last 10 lines of a file

LIN File Management with Shell Commands % ls [RETURN] % typescript you should see typescript listed among your files % cp typescript [NEW.FILENAME] [RETURN] cp = copy % ls % typescript [NEW.FILENAME] you should see typescript and whatever name you gave to the copied file listed among your files

LIN File Management with Shell Commands

LIN File Management with Shell Commands Renaming a file % mv file1 file2 [RETURN] % ls % file2

LIN File Management with Shell Commands Removing a file % rm typescript [RETURN] % ls –The file typescript should no longer be listed –There is no UNDO command for actions performed in the Shell Mode –You can remove more than one file at once: % rm file1 file2 … filen [RETURN]

LIN File Management with Shell Commands Options as arguments –Specify how a command ‘does its thing’ % rm -i typescript [RETURN] remove typescript ? The -i option informs the Shell to question your attempt to remove the specified file(s).

LIN File Management with Shell Commands Commands have online documentation, called man (manual) pages. For more information about any of these, just type % man [COMMAND] [RETURN] % man pwd

LIN File Management with Shell Commands Options as arguments –Specify how a command ‘does its thing’ –In manual instructions, optional arguments are shown in brackets following the command: % command [options]

LIN File Management with Shell Commands ls [-options] [name] -a list all files, including those starting with a "." -d list directories like other files, rather than displaying their contents -k list file sizes in kilobytes -l long (verbose) format — show permissions, ownership, size, and modification date -t sort the listing according to modification time (most recently modified files first) -X sort the files according to file extension -1 display the listing in 1 column

LIN File Management with Shell Commands files and directories beginning with a period (. ) typically hold settings for programs. Here are brief descriptions of many common dot files, generally stored in the root directory of your account:.cshrc Initialization for csh and tcsh shells.emacs Initialization and key-mappings for Emacs editor.login Startup commands for login shell.logout Commands to execute upon exiting shell.netscape/ Configuration directory for Netscape web browser.newsrc Newsgroup and article information for newsreaders.rhosts Users not requiring password to log in.signature Brief file appended to and news postings.tcshrc Initialization for tcsh shell

LIN File Management with Shell Commands Options can be combined –a verbose listing of files by last modification date: % ls -lt

LIN File Management with Shell Commands The verbose listing shows the file permissions of a given file: -rwxr-xr-x directories have a "d" in the first column regular files have a "-". the remaining 9 characters indicate owner, group, and world permissions of the file An "r" indicates it's readable "w" is writable, "x" is executable A dash in the column instead of a letter means that particular permission is turned off.

LIN File Management with Shell Commands r readable w writable x executable - permission is turned off -rwxr-xr-x a plain file that is read-write-execute by the owner, and read- execute by group and world. drwx a directory that is read-write-execute by owner, and group and world have no permissions at all.

LIN File Management with Shell Commands % chmod [permissions] [file] Changes the permissions of the named file. You can use numbers: % chmod 755 index.html The first number translates to permissions by the owner. The second is permissions for the group. The third is permissions for everyone. Number Perms no permissions 1 --x executable only 2 -w- writable only 3 -wx writable and executable 4 r--- readable only 5 r-x readable and executable 6 rw- readable and writable 7 rwx readable, writable, and executable

LIN File Management with Shell Commands A second way of setting permissions is with letters: % chmod u+rwx index.html % chmod go+rx index.html u is the owner's ("user's") permissions g is the group permissions o is "other" or world permissions. The + sign turns the stated permissions on; the — sign turns them off If you want to change a file so that it's group writable, but not readable or executable, you'd do: % chmod g+w,g-rx index.html

LIN Example of a simple shell script # This script displays the date, time, # username and current directory. echo "Date and time is:" date echo "Your username is: `whoami`" echo "Your current directory is:" pwd

LIN Example of a simple shell script # This script displays the date, time, # username and current directory. echo "Date and time is:" date echo "Your username is: `whoami`" echo "Your current directory is:" pwd

LIN Example of a simple shell script # This script displays the date, time, # username and current directory. lines beginning with a hash (#) are comments and are not interpreted by the Shell.

LIN Example of a simple shell script # This script displays the date, time, # username and current directory. echo "Date and time is:" When used as a Shell command echo echo prints its argument When echo ing multiple words, they must be placed within quotes (single or double)

LIN Example of a simple shell script # This script displays the date, time, # username and current directory. echo "Date and time is:" date echo "Your username is: `whoami`" The backquotes (`) around the command whoami illustrate the use of COMMAND SUBSTITUTION: To include the output from one command within the command line for another command, enclose the command whose output is to be included within `backquotes`.

LIN Executing the shell script Before using a file as a shell script you must change its access permissions so that you have execute permission on the file, otherwise the error message Permission deniedis displayed. To give yourself execute permission for the file containing the script use the command: % chmod u+rwx display To run the shell script, simply type its name at the prompt. The commands in the script will then execute one at a time as though you were typing them in at the terminal.

LIN Executing the shell script % chmod u-x display % display display: Permission denied.

LIN Searching for something in a file % grep [options] pattern filenames % fgrep [options] string filenames fgrep (or "fast grep") only searches for strings grep is a full-blown regular-expression matcher

LIN File Management with Shell Commands Changing to another directory % cd.. [RETURN] go up a directory tree % cd [DIRECTORY] [RETURN] change to a subdirectory % cd /tmp to change to some other directory on the system, you must type the full path name

LIN File Management with Shell Commands Create a directory % mkdir [DIRECTORY.NAME] [RETURN] Remove a directory % rmdir [DIRECTORY.NAME] [RETURN]

LIN Searching for something in a file > cd.. > cd c6932aab > ls display shakespeare > cp shakespeare ~ c6932aad > cd > ls shakespeare

LIN Searching for something in a file % grep [options] pattern filenames % fgrep [options] string filenames fgrep (or "fast grep") only searches for strings grep is a full-blown regular-expression matcher Some of the valid options are: -i case-insensitive search -n show the line# along with the matched line -v invert match, e.g. find all lines that do NOT match -w match entire words, rather than substrings

LIN Searching for something in a file with GREP % grep -inw ”thou" shakespeare find all instances of the word ”though" in the file “shakespeare”, case- insensitive but whole words and display the line numbers

LIN Grep grep '^smug' files {'smug' at the start of a line} grep 'smug$' files {'smug' at the end of a line} grep '^smug$' files {lines containing only 'smug'} grep '\^s' files {lines starting with '^s'} grep '[Ss]mug' files {search for 'Smug' or 'smug'} grep 'B[oO][bB]' files {search for BOB, Bob, BOb or BoB } grep '^$' files {search for blank lines} grep '[0-9][0-9]' file {search for pairs of numeric digits}

LIN Grep grep '[^a-zA-Z0-9] {anything not a letter or number} grep '[0-9]\{3\}-[0-9]\{4\}' { , like phone numbers} grep '^.$' {lines with exactly one character} grep '"smug"' {'smug' within double quotes} grep '"*smug"*' {'smug', with or without quotes} grep '^\.' {any line that starts with "."} grep '^\.[a-z][a-z]' {line start with "." and 2 lc letters}

LIN Egrep The version of grep that supports the full set of operators mentioned above is generally called egrep (for extended grep) % egrep '(mine|my)' shakespeare

LIN Grep % vi /class/lin6932/c6932aab/shakespeare