CSCI 330 T HE UNIX S YSTEM File operations. OPERATIONS ON REGULAR FILES 2 CSCI 330 - The UNIX System Create Edit Display Contents Display Contents Print.

Slides:



Advertisements
Similar presentations
EMT 2390L Lecture 4 Dr. Reyes Reference: The Linux Command Line, W.E. Shotts.
Advertisements

Working with Files How to create, view, copy, rename and print files.
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Jan. 27 th, 2009 Essential Unix Commands.
A Guide to Unix Using Linux Fourth Edition
CS 497C – Introduction to UNIX Lecture 24: - Simple Filters Chin-Chih Chang
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.
CS 497C – Introduction to UNIX Lecture 25: - Simple Filters Chin-Chih Chang
Guide To UNIX Using Linux Third Edition
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
CS 497C – Introduction to UNIX Lecture 13: - The File System Chin-Chih Chang
© 2006 KDnuggets [16/Nov/2005:16:32: ] "GET /jobs/ HTTP/1.1" "
Unix Files, IO Plumbing and Filters The file system and pathnames Files with more than one link Shell wildcards Characters special to the shell Pipes and.
Unix Filters Text processing utilities. Filters Filter commands – Unix commands that serve dual purposes: –standalone –used with other commands and pipes.
UNIX Filters.
Linux Commands LINUX COMMANDS.
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
Chapter 4: UNIX File Processing Input and Output.
BILKENT UNIVERSITY DEPARTMENT OF COMPUTER TECHNOLOGY AND INFORMATION SYSTEMS CTIS156 INFORMATION TECHNOLOGIES II CHAPTER 10: ADVANCED FILE PROCESSING.
©NIIT Pipes and Filters Lesson 2B / Slide 1 of 28 Introduction to Linux Pre-Assessment Questions 1.Consider the following statements: Statement A: A text.
Advanced File Processing
Lesson 11-Locating, Printing, and Archiving User Files.
BIF703 Miscellaneous Commands. File related commands  grep - print lines matching a pattern  head - output the first part of files  tail - output the.
Chapter 3: Command Line Utilities Doin’ stuff. In this chapter … Special characters Redirection More utilities than you shake a stick at.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Chapter Four UNIX File Processing. 2 Lesson A Extracting Information from Files.
Guide To UNIX Using Linux Fourth Edition
LIN 6932 Unix Lecture 6 Hana Filip. LIN 6932 HW6 - Part II solutions posted on my website see syllabus.
Introduction to Unix (CA263) File Processing. Guide to UNIX Using Linux, Third Edition 2 Objectives Explain UNIX and Linux file processing Use basic file.
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.
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
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.
Linux+ Guide to Linux Certification, Third Edition
CIT 500: IT Fundamentals Text Processing 1. Topics 1.Displaying files: cat, less, od, head, tail 2.Creating and appending 3.Concatenating files 4.Comparing.
Week 3 Exploring Linux Filesystems. Objectives  Understand and navigate the Linux directory structure using relative and absolute pathnames  Describe.
Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command to search for.
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition Chapter 5 Unix (34 slides)1 CTEC 110.
Chapter Five Advanced File Processing. 2 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command.
Module 6 – Redirections, Pipes and Power Tools.. STDin 0 STDout 1 STDerr 2 Redirections.
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 (CA263) File Processing (continued) By Tariq Ibn Aziz.
Chapter Five Advanced File Processing. 2 Lesson A Selecting, Manipulating, and Formatting Information.
ULI101 More Linux Commands Introduction to UNIX/Linux and the Internet
Agenda Basic Unix Commands (Chapters 2 & 3) Miscellaneous Commands: which, passwd, date, ps / kill Working with Files: file, touch, cat, more, less, grep,
– Introduction to the Shell 1/21/2016 Introduction to the Shell – Session Introduction to the Shell – Session 3 · Job control · Start,
ATS Programming Short Course I INTRODUCTORY CONCEPTS Tuesday, Feb 3 rd, 2009 Essential Unix Commands …the second half.
CSC 352– Unix Programming, Spring 2015 February 2015 Unix Filters.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
CSCI 330 UNIX and Network Programming Unit II Basic UNIX Usage: File System.
Lecture 1: Introduction, Basic UNIX Advanced Programming Techniques.
CIT 140: Introduction to ITSlide #1 CSC 140: Introduction to IT File Processing.
ORAFACT Text Processing. ORAFACT Searching Inside Files grep - searches for patterns within files grep [options] [[-e] pattern] filename [...] -n shows.
Lesson 6-Using Utilities to Accomplish Complex Tasks.
In the last class, Filters and delimiters The sample database pr command head and tail commands cut and paste commands.
Learning Unix/Linux Based on slides from: Eric Bishop.
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.
SIMPLE FILTERS. CONTENTS Filters – definition To format text – pr Pick lines from the beginning – head Pick lines from the end – tail Extract characters.
Linux 201 Training Module Linux Adv File Mgmt.
Tutorial of Unix Command & shell scriptS 5027
Lesson 5-Exploring Utilities
Some Linux Commands.
Chapter 6 Filters.
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
The Linux Command Line Chapter 6
Guide To UNIX Using Linux Third Edition
Tutorial of Unix Command & shell scriptS 5027
Chapter Four UNIX File Processing.
Linux Commands LINUX COMMANDS.
Presentation transcript:

CSCI 330 T HE UNIX S YSTEM File operations

OPERATIONS ON REGULAR FILES 2 CSCI The UNIX System Create Edit Display Contents Display Contents Print Others

CREATING NEW FILES 3 CSCI The UNIX System Create Regular Files Create Regular Files vim, emacs nano, etc. cat Redirect Command Output Redirect Command Output See Text Editors Section See shell Section

CREATING A FILE WITH CAT 4 CSCI The UNIX System Example: % cat > myfile This is line 1 of input Line 2 of input ^d %

DISPLAY CONTENTS OF TEXT FILES 5 CSCI The UNIX System Display Text File contents Display Text File contents cat more less pg head tail

VIEWING CONTENTS OF TEXT FILES command “cat” can be used to display/concatenate one or more files, displaying the output all at once Example: Display the contents of file “assign1.txt” % cat assign1.txt 6 CSCI The UNIX System

VIEWING CONTENTS OF TEXT FILES “more”, “less” or "pg" display the contents of one or more files one page at a time Space bar – to advance to next page b – to go back a page Enter Key – to advance to next line Example: Display the contents of file “assign1.txt” one page at a time % less assign1.txt 7 CSCI The UNIX System

VIEWING CONTENTS OF TEXT FILES “head” displays the beginning portion of indicated file(s); the default head size is 10 lines. Example: Display first 20 lines of file “assign1.txt” % head -20 assign1.txt 8 CSCI The UNIX System

VIEWING CONTENTS OF TEXT FILES “tail” displays the ending portion of indicated file(s); the default tail size is 10 lines. Example: Display last 10 lines of file “assign1.txt” % tail assign1.txt % tail -10 assign1.txt 9 CSCI The UNIX System

PRINTING FILES “lpr” send a file to the default printer printers available: csl or lpcsl(default) frl or lpfrl ucl or lpucl Example: % lpr -P frl assign1.txt 10 CSCI The UNIX System

PRETTY-PRINTING FILES “enscript” converts text file to PostScript, rtf or html default: PostScript sends output to printer Example: % enscript assign1.txt Options: -Pto specify printer -wto select output language -oto specify output file 11 CSCI The UNIX System

CHECKING PRINTING STATUS Syntax: lpq [options] Commonly used options: -P printer shows print jobs on specific printer -U user-id shows print jobs for specific user -l long format of listing -a shows print jobs on all printers Also: “lprm” to remove unwanted print job 12 CSCI The UNIX System

OPERATIONS ON TEXT & OTHER FILES 13 CSCI The UNIX System Other File Operations Other File Operations Combine contents Combine contents Extract contents Extract contents Compare files Compare files Count words Compress contents Compress contents Sort Unique lines Unique lines Encrypt/ decrypt Encrypt/ decrypt

COMBINING CONTENTS OF FILES Method 1: To vertically concatenate the contents of two or more files, use cat with output redirection (>) Syntax: cat file-1 file-2 file-3 > all-file “all-file” will contain the combined contents of file-1, file-2, and file-3 in top-down (vertical) fashion 14 CSCI The UNIX System

COMBINING CONTENTS OF FILES Method 2: To horizontally concatenate contents (columns/fields) of two or more files, use paste Syntax: paste file-1 file-2 > all-file “all-file” will contain the combined contents of file-1 and file-2 in side-by-side (horizontal) fashion 15 CSCI The UNIX System

EXTRACTING CONTENTS OF FILES To extract one or more fields from a file, use cut fields are delimited by special character default: TAB, change via –d option common: “:” must specify list of fields to be extracted option -f Example: % cut -d: -f 5 /etc/passwd 16 CSCI The UNIX System

COMPARING FILES: COMM The command named “comm” can be used to compare lines that are common in two sorted files Syntax: comm [options] file-1 file-2 The output contains three columns: Column1 contains lines unique to file-1 Column 2 contains lines unique to file-2 Column 3 contains lines common to both files 17 CSCI The UNIX System

COMPARING FILES: DIFF The command diff compares two files line by line Syntax: diff [options] file-1 file-2 If file-1 and file-2 are the same, no output is produced If file-1 and file-2 are not the same, diff reports a series of commands that can be used to convert the first file to the second file (via the “patch” command) 18 CSCI The UNIX System

DETERMINING FILE SIZE Recall: The “ls” command with the option “-l” gives the file size in bytes Use “wc” to display the size of files as number of lines, words, and characters Syntax: wc file-list Commonly used options: -l display the number of lines -w display the number of words -c display the number of characters 19 CSCI The UNIX System

FILE COMPRESSION utilities to compress and uncompress files common on Linux: gzip, gunzip file extension:.gz Example: % gzip assign1.txt % gunzip assign1.txt.gz Gzip and gunzip delete their inputs So make a copy if you want one 20 CSCI The UNIX System

COMPRESS FILE CONTENTS Bzip2 New, better compression Old compress/uncompress (.Z) Windows-compatible zip/unzip (.zip) Do not delete their input! 21 CSCI The UNIX System

SORTING FILES To sort a text file in ascending or descending order, use sort Syntax: sort [options] file-name Commonly used options: -r sort in reverse order -n numeric sort -t field delimiter -k field1[,field2] -f ignore case 22 CSCI The UNIX System

REMOVING REPEATED LINES “uniq” removes repeated lines from a sorted input file, sending unique (unrepeated) lines to standard output Syntax: uniq sorted-file-name Commonly used options: -c place a count of repeated lines at beginning of each output line -d display the repeated lines -u display the lines that are not repeated 23 CSCI The UNIX System

USER’S DISK QUOTA quota is upper limit of amount disk space number of files for each user account The command: quota -v displays the user’s disk usage and limits 2 kinds of limits: Soft limit: ex. 10MB May be exceeded for one week System will remind you when you log on Hard limit: ex. 12MB Cannot be exceeded 24 CSCI The UNIX System