1 Lecture 5 Additional useful commands COP 3353 Introduction to UNIX.

Slides:



Advertisements
Similar presentations
การใช้ระบบปฏิบัติการ UNIX พื้นฐาน บทที่ 4 File Manipulation วิบูลย์ วราสิทธิชัย นักวิชาการคอมพิวเตอร์ ศูนย์คอมพิวเตอร์ ม. สงขลานครินทร์ เวอร์ชั่น 1 วันที่
Advertisements

COMP234 Perl Printing Special Quotes File Handling.
LINUX System : Lecture 3 (English-Only Lecture) Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University Acknowledgement.
7 Searching and Regular Expressions (Regex) Mauro Jaskelioff.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Jan. 27 th, 2009 Essential Unix Commands.
CS 497C – Introduction to UNIX Lecture 29: - Filters Using Regular Expressions – grep and sed Chin-Chih Chang
Chin-Chih Chang CS 497C – Introduction to UNIX Lecture 28: - Filters Using Regular Expressions – grep and sed Chin-Chih Chang
Linux+ Guide to Linux Certification, Second Edition
CIS 240 Introduction to UNIX Instructor: Sue Sampson.
CS 497C – Introduction to UNIX Lecture 13: - The File System Chin-Chih Chang
QUOTATION This chapter teaches you about a unique feature of the shell programming language: the way it interprets quote characters. Basically, the shell.
UNIX. find command ● The find command is used to locate files on a Unix or Linux system. find will search any set of directories you specify for files.
UNIX Filters.
MCB Lecture #3 Sept 2/14 Intro to UNIX terminal.
BILKENT UNIVERSITY DEPARTMENT OF COMPUTER TECHNOLOGY AND INFORMATION SYSTEMS CTIS156 INFORMATION TECHNOLOGIES II CHAPTER 10: ADVANCED FILE PROCESSING.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
Regular Expressions A regular expression defines a pattern of characters to be found in a string Regular expressions are made up of – Literal characters.
Brief introduction to UNIX A. Emerson CINECA, High Performance Systems.
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.
Offline File Storage. Module 12 Offline File Storage ♦ Introduction Backup is usually done by first collecting all the data in a single archive file,
Overview of the grep Command Alex Dukhovny CS 265 Spring 2011.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
System Programming Regular Expressions Regular Expressions
Lesson 11-Locating, Printing, and Archiving User Files.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Unix Talk #2 (sed). 2 You have learned…  Regular expressions, grep, & egrep  grep & egrep are tools used to search for text in a file  AWK -- powerful.
Unix programming Term: III B.Tech II semester Unit-II PPT Slides Text Books: (1)unix the ultimate guide by Sumitabha Das (2)Advanced programming.
Title Slide CSS 404/504 The UNIX Operating System (2) By Ralph B. Bisland, Jr.
Dedan Githae, BecA-ILRI Hub Introduction to Linux / UNIX OS MARI eBioKit Workshop; Nov , 2014.
Linux Operations and Administration
CS 497C – Introduction to UNIX Lecture 7: General-Purpose Utilities Chin-Chih Chang
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Jozef Goetz, expanded by Jozef Goetz, 2009 Credits: Parts of the slides are based on slides created by UNIX textbook authors, Syed M. Sarwar, Robert.
1 Day 5 Additional Unix Commands. 2 Important vs. Not Often in Unix there are multiple ways to do something. –In this class, we will learn the important.
(Stream Editor) By: Ross Mills.  Sed is an acronym for stream editor  Instead of altering the original file, sed is used to scan the input file line.
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 Unit 10 Linux.
Introduction to Unix – CS 21 Lecture 6. Lecture Overview Homework questions More on wildcards Regular expressions Using grep Quiz #1.
Agenda Regular Expressions (Appendix A in Text) –Definition / Purpose –Commands that Use Regular Expressions –Using Regular Expressions –Using the Replacement.
BIF713 Additional Utilities. Linux Utilities  You have learned many Linux commands. Here are some more that you can use:  Data Manipulation (Reg Exps)
Introduction to Unix – CS 21 Lecture 12. Lecture Overview A few more bash programming tricks The here document Trapping signals in bash cut and tr sed.
Ant & Jar Ant – Java-based build tool Jar – pkzip archive, that contains metadata (a manifest file) that the JRE understands.
1 Lecture 9 Shell Programming – Command substitution Regular expressions and grep Use of exit, for loop and expr commands COP 3353 Introduction to UNIX.
By Corey Stokes 9/14/10. What is grep? Global Regular Expression Print grep is a command line search utility in Unix Try: Search for a word in a.cpp file.
BASH – Text Processing Utilities Erick, Joan © Sekolah Tinggi Teknik Surabaya 1.
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.
What is grep ?  % man grep  DESCRIPTION  The grep utility searches text files for a pattern and prints all lines that contain that pattern. It uses.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Feb 3 rd, 2009 Essential Unix Commands …the second half.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Chapter Linux Basics. Acknowledgements This presentation was prepared by – Banyat Settapanich – Bahran Madaen This presentation will be updated later.
Agenda The Linux File System (chapter 4 in text) Setting Access Permissions Directory vs File Permissions chmod Utility Symbolic Method Absolute Method.
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.
Filters and Utilities. Notes: This is a simple overview of the filtering capability Some of these commands are very powerful ▫Only showing some of the.
Agenda The Linux File System (chapter 4 in text) Linking Files Hard Links / Symbolic Links Disk Storage Checking for Disk Space (df / du) Archiving (Backing.
tar: The tape archive program _______________________ Amber Jain IC-2K7-05 _______________________.
PROGRAMMING THE BASH SHELL PART III by İlker Korkmaz and Kaya Oğuz
LINUX LANGUAGE MULTIPLE CHOICE QUESTION SET-5
Lecture 9 Shell Programming – Command substitution
INTRODUCTION TO UNIX: The Shell Command Interface
Basic UNIX OLC Training.
The ‘grep’ Command Colin Masterson.
Lecture 5 Additional useful commands COP 3353 Introduction to UNIX 1.
Unix Talk #2 (sed).
New Perspectives on Windows XP
Chin-Chih Chang CS 497C – Introduction to UNIX Lecture 28: - Filters Using Regular Expressions – grep and sed Chin-Chih Chang
Prepared by, Mr. Satish Pise
Regular Expressions grep Familiy of Commands
Lecture 5 Additional useful commands COP 3353 Introduction to UNIX 1.
Presentation transcript:

1 Lecture 5 Additional useful commands COP 3353 Introduction to UNIX

2 diff diff compares two text files ( can also be used on directories) and prints the lines for which the files differ. The format is as follows: diff [options] Some options –[-b] Treats groups of spaces as one –[-i] Ignores case –[-r] Includes directories in comparison –[-w] Ignores all spaces and tabs – - Specifies one file to compare – - Specifies other file to compare Example: diff -w testprog1.c testprog2.c

3 Example files (from Wikipedia)‏ (original file)‏ This part of the document has stayed the same from version to version. It shouldn't be shown if it doesn't change. Otherwise, that would not be helping to compress the size of the changes. This paragraph contains text that is outdated. It will be deleted in the near future. It is important to spell check this dokument. On the other hand, a misspelled word isn't the end of the world. Nothing in the rest of this paragraph needs to be changed. Things can be added after it. (new file)‏ This is an important notice! It should therefore be located at the beginning of this document! This part of the document has stayed the same from version to version. It shouldn't be shown if it doesn't change. Otherwise, that would not be helping to compress anything. It is important to spell check this document. On the other hand, a misspelled word isn't the end of the world. Nothing in the rest of this paragraph needs to be changed. Things can be added after it. This paragraph contains important new additions to this document.

4 Result of diff (from Wikipedia)‏ 0a1,6 > This is an important > notice! It should > therefore be located at > the beginning of this > document! > 8,14c14 < compress the size of the < changes. < < This paragraph contains < text that is outdated. < It will be deleted in the < near future. --- > compress anything. 17c17 < check this dokument. On --- > check this document. On 24a25,28 > > This paragraph contains > important new additions > to this document. In this traditional output format, a stands for added, d for deleted and c for changed. Line numbers of the original file appear before a/d/c and those of the modified file appear after. Angle brackets appear at the beginning of lines that are added, deleted or changed. Addition lines are added to the original file to appear in the new file. Deletion lines are deleted from the original file to be missing in the new file. By default, lines common to both files are not shown. Lines that have moved will show up as added on their new location and as deleted on their old location.

5 cmp and gzip cmp –Compares two files byte by byte and tells you where they differ. Generally used for binary and executable files. –usage: cmp myfile1.o myfile2.o gzip / gunzip –this is one of the compression utilities that reduces the size of a file to take up less space on your drive. It should be used with some care. There are a lot of options available. –Examples to compress and restore a file called bigfile: gzip bigfile (compresses file, flag -v can be used for verbose mode to give information; note: original file is gone! The compressed file has an extension of.gz gzip -d bigfile.gz (this restores a.gz file)‏ gunzip bigfle.gz (same as line above)‏ –When you experiment with this use copies of files rather than the originals until you are comfortable with how gzip works!

6 grep grep is a very useful utility that searches files for a particular pattern. The pattern can be a word, a string enclosed in single quotes, or a regular expression. usage –grep int *.c (find all occurences of the pattern ‘int’ in all files with a.c extenstion)‏ –grep ‘main()’ testprog1.c (enclosing the pattern in quotes is useful when using special characters)‏ –grep ‘m.*n’ myfile (the. matches a single character, the.* matches any number of characters; this finds anything starting with an m and ending with an n)‏ The way that regular expressions can be described is somewhat complex in grep: see the following tutorial for more help: grep has many options; a few are noted below -iignore case -ndisplay the line numbers -ldisplay only names of files and not actual lines -Ppattern is a Perl regular expression

Some grep patterns Bracketed expressions [1357] matches 1 or 3 or 5 or 7 [^1357] with a beginning ^ matches not (1,3,5,7)‏ Range expressions [b-g] matches b, c, d, e, f, g Named classes of expressions [:digit:], [:alnum:] Special symbols ? The preceding item is optional and matched at most once. * The preceding item will be matched zero or more times. + The preceding item will be matched one or more times.. This matches any single character 7

Some grep patterns continued Matching at the beginning and end ^ matches the beginning of the line, thus ^#include would math any lines with a #include at the beginning of the line. $ matches the end of line \< matches the beginning of a word \> matches the end of a word | the or operator grep dog | cat egrep and fgrep are extended versions 8

9 tar Tar is a utility for creating and extracting archives. It is very useful for archiving files on disk, sending a set of files over the network, and for compactly making backups General form: tar options filenames Commonly used Options -cinsert files into a tar file -f use the name of the tar file that is specified -voutput the name of each file as it is inserted into or extracted from a tar file -xextract the files from a tar file -tlist contents of an archive -zwill gzip / gunzip if necessary

10 Creating an Archive with Tar The typical command used to create an archive from a set of files is illustrated below. Not that each specified filename can also be a directory. Tar will insert all files in that directory and any subdirectories. The f flag is used to create an archive file with a specific name (usually named with an extension of.tar). Examples tar -cvf proj.tar proj If proj is a directory this will insert the directory and all files and subdirectories (recursively) with the name of the archive being proj.tar Note that if proj.tar already existed it will simply be overwritten; previous information will be lost. tar -cvf prog.tar *.c *.h All files ending in.c or.h will be archived in prog.tar

11 Extracting files from a Tar Archive The typical tar command used to extract the files from a tar archive is illustrated below. The extracted files have the same name, permissions, and directory structure as the original files. If they are opened by another user (archive sent by ) the user id becomes that of the user opening the tar archive. Examples tar -xvf proj.tar Extract all files from proj.tar into the current directory. Note that proj.tar remains in the current directory. tar -xvzf proj.tar.gz Extract files but also unzip files in the process