Guide to unix using linux fourth edition
This presentation is the property of its rightful owner.
Sponsored Links
1 / 27

Guide To UNIX Using Linux Fourth Edition PowerPoint PPT Presentation


  • 93 Views
  • Uploaded on
  • Presentation posted in: General

Guide To UNIX Using Linux Fourth Edition. Chapter Four UNIX/Linux File Processing. Objectives. Explain UNIX and Linux file processing Use basic file manipulation commands to create, delete, copy, and move files and directories

Download Presentation

Guide To UNIX Using Linux Fourth Edition

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Guide to unix using linux fourth edition

Guide To UNIX Using LinuxFourth Edition

Chapter Four

UNIX/Linux File Processing

CTEC 110


Objectives

Objectives

Explain UNIX and Linux file processing

Use basic file manipulation commands to create, delete, copy, and move files and directories

Employ commands to combine, cut, paste, rearrange, and sort information in files

CTEC 110


Objectives continued

Objectives (continued)

Create a script file

Use the join command to link files using a common field

Use the awk command to create a professional-looking report

CTEC 110


Unix and linux file processing

UNIX and Linux File Processing

Based on the approach that files should be treated as nothing more than character sequences

Because you can directly access each character, you can perform a range of editing tasks – this offers flexibility in terms of file manipulation

CTEC 110


Reviewing unix linux file types

Reviewing UNIX/Linux File Types

  • Regular files, also known as ordinary files

    • Create information that you maintain and manipulate, and include ASCII and binary files

  • Directories

    • System files for maintaining file system structure

CTEC 110


Reviewing unix linux file types continued

Reviewing UNIX/Linux File Types (continued)

  • Special files

    • Character special files relate to serial I/O devices

    • Block special files relate to devices such as disks

CTEC 110


Understanding file structures

Understanding File Structures

  • Files can be structured in many ways depending on the kind of data they store

  • UNIX/Linux store data, such as letters and product records, as flat ASCII files

  • Three kinds of regular files are

    • Unstructured ASCII character

    • Unstructured ASCII records

    • Unstructured ASCII trees

CTEC 110


Guide to unix using linux fourth edition

CTEC 110


Processing files

Processing Files

UNIX/Linux processes commands by receiving input from a standard input device (e.g. keyboard) and sending it to a standard output device (e.g. monitor)

System administrators and programmers refer to standard input as stdin, standard output as stdout

When UNIX/Linux detect errors, they send data to standard error (stderr, the monitor)

CTEC 110


Using input and error redirection

Using Input and Error Redirection

  • You can use redirection operators to retrieve input from something other than the standard input device and send output to something other than the standard output device

  • Examples of redirection

    • Redirect the ls command output to a file, instead of to the monitor (or screen)

    • Redirect a program that receives input from the keyboard to receive input from a file instead

    • Redirect error messages to files, instead of to the screen by default

CTEC 110


Manipulating files

Manipulating Files

  • When you manipulate files, you work with the files themselves, as well as their contents

  • Create files using output redirection

    • cat command - concatenate text via output redirection

    • without a command - > filename

    • touch command - creates empty files

CTEC 110


Manipulating files continued

Manipulating Files (continued)

  • Delete files when no longer needed

    • rm command - permanently removes a file or an empty directory

    • The -r option of the rm command will remove a directory and everything it contains

  • Copy files as a means of back-up or as a means to assist with new file creation

    • cp command - copies the file(s) specified by the source path to the location specified by the destination path

CTEC 110


Manipulating files continued1

Manipulating Files (continued)

  • Move files from directory to directory

    • mv command - removes file from one directory and places it in another

  • Finding a file helps you locate it in the directory structure

    • find command - searches for the file that has the name you specify

CTEC 110


Manipulating files continued2

Manipulating Files (continued)

  • Combining files using output redirection

    • cat command - concatenate text of two different files via output redirection

    • paste command - joins text of different files in side by side fashion

CTEC 110


Guide to unix using linux fourth edition

The paste command joins text of different files in side by side fashion

CTEC 110


Guide to unix using linux fourth edition

Extracting fields of a file using output redirection: the cut command removes specific columns or fields from a file

CTEC 110


Manipulating files continued3

Manipulating Files (continued)

  • Sorting the contents of a file

    • sort command - sorts a file’s contents alphabetically or numerically

    • the sort command offers many options:

      • You can sort the contents of a file and redirect the output to another file

      • Utilizing a sort key provides the option of sorting on a field position within each line

CTEC 110


Guide to unix using linux fourth edition

CTEC 110


Creating script files

Creating Script Files

UNIX/Linux users create shell script files to contain commands that can be run sequentially as a set – this helps with the issues of command automation and re-use of command actions

UNIX/Linux users use the vi editor to create script files, then make the script executable using the chmod command with the x argument

CTEC 110


Guide to unix using linux fourth edition

CTEC 110


Using the join command on two files

Using the join Command on Two Files

Sometimes you want to link the information in two files

The join command is often used in relational database processing

The join command associates information in two different files on the basis of a common field or key in those files

CTEC 110


A brief introduction to the awk program

A Brief Introduction to theAwk Program

Awk, a pattern-scanning and processing language helps to produce professional-looking reports

Awk provides a powerful programming environment that can perform actions on files that are difficult to duplicate with a combination of other commands

CTEC 110


A brief introduction to the awk program continued

A Brief Introduction to theAwk Program (continued)

Awk checks to see if the input records in specified files satisfy a pattern

If so, awk executes a specified action

If no pattern is provided, awk applies the action to every record

CTEC 110


Chapter summary

Chapter Summary

UNIX/Linux supports regular files, directories, and character and block special files

File structures depend on data being stored

UNIX/Linux receives input from the standard input device (keyboard, stdin) and sends output to the standard output device (monitor, stdout)

CTEC 110


Chapter summary continued

Chapter Summary (continued)

touch updates a file’s time and date stamps and creates empty files

rmdir removes empty directories

cut extracts specific columns or fields from a file

paste combines two or more files

sort sorts a file’s contents

CTEC 110


Chapter summary continued1

Chapter Summary (continued)

To automate command processing, include commands in a script file

join extracts data from two files sharing a common field and uses this field to join the two files

Awk is a pattern-scanning and processing language useful for creating a formatted report with a professional look

CTEC 110


Chapter 4 unix exercises

Chapter 4 Unix Exercises

  • Work through Hands-on Projects at end of chapter 4

  • Canvas: Review Questions 4

    • (Do not do questions 22,23,24 and 25)

  • Read chapter 5 before next class session

  • Quiz 4 Unix…

CTEC 110


  • Login