Presentation is loading. Please wait.

Presentation is loading. Please wait.

The Essence of UNIX and Linux

Similar presentations


Presentation on theme: "The Essence of UNIX and Linux"— Presentation transcript:

1 The Essence of UNIX and Linux
Chapter One The Essence of UNIX and Linux Guide To UNIX Using Linux Fourth Edition Chapter 1 Unix (42 slides) 1

2 Objectives Explain operating systems, including PC, mainframe, and network operating systems Describe the UNIX and Linux operating systems Explain the purpose of UNIX/Linux shells Understand how to select user names and passwords Connect to UNIX/Linux using Telnet or SSH Chapter 1 Unix (42 slides) CTEC 110 2

3 Objectives (continued)
Use basic UNIX/Linux commands and command- line editing features Explain the role of a system administrator Change your password for security Use multiple commands to view the contents of files Redirect output to a file Chapter 1 Unix (42 slides) CTEC 110 3

4 Understanding Operating Systems
Operating System (OS) The most fundamental computer program Enables you to store information, process raw data, use application software, compile your own programs, and access attached hardware, such as a printer or keyboard Chapter 1 Unix (42 slides) CTEC 110 4

5 Understanding Operating Systems
Chapter 1 Unix (42 slides) CTEC 110 5

6 PC Operating Systems A personal computer (PC) OS conducts all I/O, processing, and storage operations on a stand-alone computer Chapter 1 Unix (42 slides) CTEC 110 6

7 Mainframe Operating Systems
A mainframe OS controls a large computer system with multiple processors for I/O, processing, and storage operations for many users Chapter 1 Unix (42 slides) CTEC 110 7

8 Network Operating Systems
A network OS controls the operations of a server computer (host), which accepts requests from user programs running on other computers (clients) Chapter 1 Unix (42 slides) CTEC 110 8

9 Server-based vs. peer-to-peer networks
Server-based network Centralized processing approach Data and applications server resident If server fails, entire network fails Peer-to-peer Distributed processing approach Data and applications workstation resident Each system is both a server and a client Chapter 1 Unix (42 slides) CTEC 110 9

10 Introducing the UNIX and Linux Operating Systems
UNIX/Linux can be used on systems functioning as: Dedicated servers or client workstations in a server-based network Client/server workstations connected to a peer-to-peer network Stand-alone workstations not connected to a network Chapter 1 Unix (42 slides) CTEC 110 10

11 Introducing the UNIX and Linux Operating Systems (continued)
UNIX/Linux is a multi-user system UNIX/Linux is a multitasking system Can execute more than one program at a time UNIX/Linux is a portable operating system Used in many computing environments Chapter 1 Unix (42 slides) CTEC 110 11

12 A Brief History of UNIX Bell Labs originally developed UNIX in the late 1960s and early 1970s Distributed in source code form Universities modified the code to work on different machines Two standard versions of UNIX evolved System V (Bell Labs) Berkeley Software Distribution (BSD) Chapter 1 Unix (42 slides) CTEC 110 12

13 UNIX Concepts The interface between user and OS
Shell The interface between user and OS Hierarchical Structure Directory and subdirectory organization Layered components Layers of software surround the computer’s inner core Chapter 1 Unix (42 slides) CTEC 110 13

14 Chapter 1 Unix (42 slides) CTEC 110 14

15 Linux and UNIX Linux is UNIX-like
Not written from traditional UNIX code Linux is original code Includes POSIX standards Other Linux information Created by Linus Torvalds Offers all the complexity of UNIX Linux can coexist with other OSs Chapter 1 Unix (42 slides) CTEC 110 15

16 Introducing UNIX/Linux Shells
A shell is a UNIX/Linux program that interprets the commands you enter from the keyboard Chapter 1 Unix (42 slides) CTEC 110 16

17 Choosing Your Shell Shells interpret commands and act as first-class programming languages A default shell is associated with your account when created; Bash is the default shell in Linux Some UNIX/Linux shells: Bourne, Korn, C shell, Bash Can switch from shell to shell Chapter 1 Unix (42 slides) CTEC 110 17

18 Choosing User Names and Passwords
To use UNIX/Linux, a user must log in by providing a unique user name and password UNIX/Linux system administrators create accounts by adding user names and passwords Users log in to UNIX or Linux systems as long as they have accounts on the workstation or host (server) computer Chapter 1 Unix (42 slides) CTEC 110 18

19 Connecting to UNIX/Linux Using Telnet or SSH
Remotely through Telnet (Use SSH Mostly Now!) Through network client software As peer on peer-to-peer network On a stand-alone PC Through a dumb terminal Chapter 1 Unix (42 slides) CTEC 110 19

20 Connecting to UNIX Using Telnet
Telnet is terminal emulation software Connects your PC to a server, or host PC could be running UNIX, Linux, Windows OS, or Macintosh OS Once connected to a UNIX/Linux host, work with UNIX/Linux may begin Uses IP addresses or domain names to access remote systems Chapter 1 Unix (42 slides) CTEC 110 20

21 Secure Shell (SSH) Developed for UNIX/Linux systems to provide authentication security for TCP/IP applications, such as FTP and Telnet Can encrypt communications as they go across a network or the Internet openSSH includes protocols and software for free distribution on UNIX/Linux systems Chapter 1 Unix (42 slides) CTEC 110 21

22 Logging In to UNIX/Linux
Log in by entering username and password when UNIX/Linux system booted or connected to Enter at prompt (command-line mode) or into login box (GUI mode) Now commands can be issued at the command prompt Chapter 1 Unix (42 slides) CTEC 110 22

23 Logging In to UNIX/Linux (continued)
With a standalone computer and an X Window desktop such as GNOME, you must open a terminal window to access the command prompt Chapter 1 Unix (42 slides) CTEC 110 23

24 Using Commands To interact with UNIX/Linux, a command is entered at the command prompt UNIX/Linux is case-sensitive and most commands are typed in lower case Two categories of commands User-level: perform tasks System administration: system management Chapter 1 Unix (42 slides) CTEC 110 24

25 Using Commands (continued)
The date command Displays the system date, which the system administrator maintains The cal command Shows the system calendar Chapter 1 Unix (42 slides) CTEC 110 25

26 Using Commands (continued)
Chapter 1 Unix (42 slides) CTEC 110 26

27 Using Commands (continued)
Chapter 1 Unix (42 slides) CTEC 110 27

28 Using Commands (continued)
The who Command To get information about who is logged in Useful for administrators and users The clear Command Clears the screen The whatis command Displays a brief description of a command for help purposes Chapter 1 Unix (42 slides) CTEC 110 28

29 Using Commands (continued)
The man program displays the UNIX/Linux online reference manual, called the man pages, for help purposes Chapter 1 Unix (42 slides) CTEC 110 29

30 Using Commands (continued)
Command-line editing Certain keystrokes perform command-line editing (shell dependent) Multiple command entries More than one command on one line by separating with a semicolon(;) Chapter 1 Unix (42 slides) CTEC 110 30

31 Using Commands (continued)
Command-line history Use up and down arrow keys to scroll through command history Logging out ends your current process and indicates to UNIX that you are finished Logging out is shell dependent Bourne, Korn, Bash – exit command C shell – logout command Chapter 1 Unix (42 slides) CTEC 110 31

32 Understanding the Role of the UNIX/Linux System Administrator
System administrator manages the UNIX/Linux system Adds users and deletes old accounts Also called the superuser Unlimited permission to alter system Unique user name: root Prompt ends with # (pound) symbol Chapter 1 Unix (42 slides) CTEC 110 32

33 Understanding the Role of the UNIX/Linux System Administrator (continued)
The System Administrator’s Command Line root]# The Ordinary User’s Command Line username] $ Chapter 1 Unix (42 slides) CTEC 110 33

34 Changing Passwords For security purposes, changing passwords is necessary Use the passwd command UNIX/Linux allows new password if: The new password differs by at least three characters It has six or more characters, including at least two letters and one number It is different from the user name Chapter 1 Unix (42 slides) CTEC 110 34

35 Viewing Files Using the cat, more, less, head, and tail Commands
Use cat, more, and less to view an entire file contents cat displays a whole file at one time more displays a file one screen at a time, allowing scroll down less displays a file one screen at a time, allowing scroll down and up Chapter 1 Unix (42 slides) CTEC 110 35

36 Viewing Files Using the cat, more, less, head, and tail Commands (continued)
Use head and tail to view the first few or last few lines of a file head displays the first few lines (10 lines) tail displays the last few lines (10 lines) Chapter 1 Unix (42 slides) CTEC 110 36

37 Redirecting Output The greater than sign (>) is called a redirection symbol Create a new file or overwrite an existing file by attaching (>) to a command that produces output To append to an existing file, use two redirection symbols (>>) Chapter 1 Unix (42 slides) CTEC 110 37

38 Chapter Summary OS controls all computer resources and provides the base upon which application programs can be used or written A server-based network is centralized (handled by the system administrator) A peer-to-peer network is decentralized UNIX/Linux are multi-user, multitasking Chapter 1 Unix (42 slides) CTEC 110 38

39 Chapter Summary (continued)
UNIX/Linux systems can be configured as servers, client workstations, client/server workstations, or stand-alone The concept of the layered components that make up an OS originated with UNIX Linux is a UNIX-like OS for a PC You communicate with the OS programs through an interpreter called the shell Chapter 1 Unix (42 slides) CTEC 110 39

40 Chapter Summary (continued)
The system administrator sets up accounts for users that supply a username and password You work with UNIX by typing commands that you can learn by referring to the online manual called man pages Chapter 1 Unix (42 slides) CTEC 110 40

41 Chapter Summary (continued)
Most shells provide basic command-line editing capabilities and keep a history of your most recently used commands You can view the contents of files with view commands such as cat, less, more, head, and tails Chapter 1 Unix (42 slides) CTEC 110 41

42 Chapter 1 Unix Exercises
Work through Hands-on Projects at end of chapter 1 Canvas: Review Questions 1 (Do not do questions 22,23,24 and 25 on All Unix Chapters!) Read chapter 2 before next class session Quiz 1 UNIX… Chapter 1 Unix (42 slides) CTEC 110 42

43 Exploring the UNIX/Linux File Systems and File Security
Chapter Two Exploring the UNIX/Linux File Systems and File Security Guide To UNIX Using Linux Fourth Edition 43 CTEC 110 Chapter 2 Unix (31 slides)

44 Objectives Discuss UNIX/Linux file systems
Explain partitions and inodes Understand the elements of the root hierarchy Use the mount command Explain and use paths, pathnames, and prompts Navigate the file system Create and remove directories Copy and delete files Configure file permissions 44 CTEC 110 Chapter 2 Unix (31 slides)

45 Understanding UNIX/Linux File Systems
File: basic component for data storage UNIX/Linux considers everything to be a file A file system is UNIX/Linux’s way of organizing files on mass storage devices A physical file system is a section of the hard disk that has been formatted to hold files The file system is organized in a hierarchical structure (inverted tree) 45 CTEC 110 Chapter 2 Unix (31 slides)

46 Understanding UNIX/Linux File Systems (continued)
46 CTEC 110 Chapter 2 Unix (31 slides)

47 Understanding the Standard Tree Structure
The structure starts at the root level Root is the name of the file at this basic level and it is denoted by the slash character (/) Directory: file that can contain other files and directories Subdirectory: directory within a directory The subdirectory is considered the child of the parent directory 47 CTEC 110 Chapter 2 Unix (31 slides)

48 Using UNIX/Linux Partitions
The section of the disk that holds a file system is called a partition When installing UNIX/Linux, one of the first tasks is deciding how to partition a storage device, or hard disk Hard disks may have many partitions UNIX/Linux partitions are given names LINUX uses hda1 and hda2 48 CTEC 110 Chapter 2 Unix (31 slides)

49 Using UNIX/Linux Partitions (continued)
Storage devices are called peripheral devices Peripheral devices connect to the computer through electronic interfaces IDE: Integrated Drive Electronics SCSI: Small Computer System Interface 49 CTEC 110 Chapter 2 Unix (31 slides)

50 50 CTEC 110 Chapter 2 Unix (31 slides)

51 Setting Up Hard Disk Partitions
Partitioning your hard disk provides organized space for file systems At least 3 partitions (root, swap, /boot) often recommended Root partition holds root file system directory (/), size depends on installation but often ranges between 1.2 to 5+ GB 51 CTEC 110 Chapter 2 Unix (31 slides)

52 Setting Up Hard Disk Partitions (continued)
Swap partition acts as a memory extension, often has same size as RAM, enables virtual memory /boot partition used to store the os files comprising the kernel and is relatively small Other used partitions include /usr, /home, /var 52 CTEC 110 Chapter 2 Unix (31 slides)

53 Using Inodes Inodes are associated with directories and files in ufs and ext file systems An inode contains the name, general information, and location information (a pointer) for a file or directory A superblock contains information about the block layout on a specific partition 53 CTEC 110 Chapter 2 Unix (31 slides)

54 Exploring the Root Hierarchy
UNIX/Linux must mount a file system before any programs can access files on it To mount a file system is to connect it to the directory tree structure The root file system is mounted by the kernel when the system starts 54 CTEC 110 Chapter 2 Unix (31 slides)

55 Exploring the Root Hierarchy (continued)
The root directory contains sub-directories that contain files: /bin contains binaries, or executables needed to start the system and perform system tasks /boot contains files needed by the bootstrap loader as well as kernel images /dev contains system device reference files 55 CTEC 110 Chapter 2 Unix (31 slides)

56 56 CTEC 110 Chapter 2 Unix (31 slides)

57 Exploring the Root Hierarchy (continued)
Root subdirectories continued: /etc contains configuration files that the system uses when the computer starts /lib contains kernel modules, security information, and the shared library images /mnt contains mount points for temporary mounts by the system administrator /proc is a virtual file system allocated in memory only 57 CTEC 110 Chapter 2 Unix (31 slides)

58 Exploring the Root Hierarchy (continued)
Root subdirectories continued: /root is the home directory of the root user, or the system administrator /sbin contains essential network programs used only by the system administrator /tmp is a temporary place to store data during processing cycles /var contains subdirectories which have sizes that often change, such as error logs 58 CTEC 110 Chapter 2 Unix (31 slides)

59 Using the mount Command
Users can access mounted file systems which they have permission to access Additional file systems can be mounted at any time using the mount command To ensure system security, only the root user uses the mount command 59 CTEC 110 Chapter 2 Unix (31 slides)

60 Using Paths, Pathnames, and Prompts
To specify a file or directory, use its pathname, which follows the branches of the file system to the desired file A forward slash (/) separates each directory name The UNIX/Linux command prompt may indicate your location within the file system Use the UNIX/Linux pwd command to display the current path name 60 CTEC 110 Chapter 2 Unix (31 slides)

61 61 CTEC 110 Chapter 2 Unix (31 slides)

62 62 CTEC 110 Chapter 2 Unix (31 slides)

63 Navigating the File System
To navigate the UNIX/Linux directory structure, use the cd (change directory) command UNIX/Linux refers to a path as either: Absolute - begins at the root level and lists all subdirectories to the destination file Relative - begins at your current working directory and proceeds from there 63 CTEC 110 Chapter 2 Unix (31 slides)

64 Using Dot and Dot Dot Addressing Techniques
UNIX/Linux interpret a single dot (.) to mean the current working directory Two dots (..) mean the parent directory cd .. moves you up a level in the directory structure 64 CTEC 110 Chapter 2 Unix (31 slides)

65 Listing Directory Contents
The ls (list) command displays a directory’s contents, including files and subdirectories 65 CTEC 110 Chapter 2 Unix (31 slides)

66 Using Wildcards A wildcard is a special character that is used as a placeholder The * wildcard represents any group of characters in a file name The ? wildcard represents a single character in a file name 66 CTEC 110 Chapter 2 Unix (31 slides)

67 Creating and Removing Directories and Files
mkdir (make directory) command Create a new directory rmdir (remove directory) command Delete an empty directory cp (copy) command Copy files from one directory to another rm (remove) command Delete files 67 CTEC 110 Chapter 2 Unix (31 slides)

68 Configuring File Permissions for Security
68 CTEC 110 Chapter 2 Unix (31 slides)

69 Configuring File Permissions for Security (continued)
Owner has read w Owner has write x Owner has execute Group has read - Group does not have write Group has execute Others have read Others do not have write Others have execute 69 CTEC 110 Chapter 2 Unix (31 slides) 69

70 Configuring File Permissions for Security (continued)
chmod command To set file permissions Settings are read (r), write (w), execute (x) The three types of users are owners(users), groups, and others(world) or simply (ugo) Setting permissions to directories Use the execute (x) to grant access 70 CTEC 110 Chapter 2 Unix (31 slides)

71 Chapter 2 Unix Exercises
Work through Hands-on Projects at end of chapter 2 Canvas: Review Questions 2 (Do not do questions 22,23,24 and 25) Read chapter 3 before next class session Quiz 2 Unix… 73 CTEC 110 Chapter 2 Unix (31 slides)

72 Chapter 3 Mastering Editors
Guide To UNIX Using Linux Fourth Edition 74 CTEC 110 Chapter 3 (40 slides) 74

73 Objectives Explain the basics of UNIX/Linux files, including ASCII, binary, and executable files Understand the types of editors Create and edit files using the vi editor Create and edit files using the Emacs editor 75 CTEC 110 Chapter 3 (40 slides) 75

74 Understanding UNIX/Linux Files
Almost everything you create in UNIX/Linux is stored in a file Bit: binary digit In one of two states: 0 or 1 Machine language: exclusive use of 0s and 1s as a way to communicate with computer Used by earliest programmers 76 CTEC 110 Chapter 3 (40 slides) 76

75 ASCII Text Files Byte (binary term): string of eight bits
A byte can be configured into fixed patterns of bits ASCII: American Standard Code for Information Interchange 256 different characters Unicode Supports up to 65,536 characters Text files: contain nothing but printable characters Binary files: contain nonprintable characters Example: machine instructions 77 CTEC 110 Chapter 3 (40 slides)

76 Look at Page 113 78 CTEC 110 Chapter 3 (40 slides)

77 Binary Files Some things cannot be represented with ASCII codes
Binary files are used instead Example: graphic files include bit patterns Bitmap: made of rows and columns of dots 79 CTEC 110 Chapter 3 (40 slides)

78 Executable Program Files
Text files containing program code are compiled into machine-readable language Scripts are files containing commands Typically interpreted, not compiled Executables: compiled and interpreted files that can be run 80 CTEC 110 Chapter 3 (40 slides)

79 Using Editors Editor: program for creating and modifying files containing source code, text, data, memos, etc. Text editor: a simplified word-processing program Used to create and edit documents Two text editors normally included in UNIX/Linux are screen editors vi Emacs Line editor: works with one line (or group of lines) at a time 81 CTEC 110 Chapter 3 (40 slides)

80 Using the vi Editor vi is a visual editor vi is also a modal editor
Supports three modes Insert mode Accessed by typing “i” Command mode Accessed by typing Esc Extended (ex) command set mode Accessed by typing “:” in command mode Download the vi editor document on Blackboard for reference 82 CTEC 110 Chapter 3 (40 slides)

81 Creating a New File in the vi Editor
83 CTEC 110 Chapter 3 (40 slides)

82 Inserting Text When you start vi, you are in command mode
To insert text in your file, switch to insert mode Use i (insert) command To return to command mode, press Esc 84 CTEC 110 Chapter 3 (40 slides)

83 Repeating a Change Use a period (.) to repeat the most recent change you made Repeat command Works in command mode 85 CTEC 110 Chapter 3 (40 slides)

84 Moving the Cursor To move cursor use arrow keys (command/insert mode) or (in command mode) use: 86 CTEC 110 Chapter 3 (40 slides)

85 Deleting Text Deletion commands available (command mode)
dd is used for “cutting” text Use “yank” (yy) command for “copying” text 87 CTEC 110 Chapter 3 (40 slides)

86 Undoing a Command Type u to use the undo command Example:
If you delete a few lines from a file by mistake, type u to restore the text 88 CTEC 110 Chapter 3 (40 slides)

87 Searching for a Pattern
To search forward for a pattern of characters: Type a forward slash (/) Type the pattern you are seeking Press Enter Examples: /\<top, /s..n, /pas[st], /!$ 89 CTEC 110 Chapter 3 (40 slides)

88 Searching and Replacing
Screen-oriented commands execute at the location of the cursor Line-oriented commands require you to specify an exact location (an address) for the operation Preceded by a colon (:) Operate in ex mode Used for commands that perform more than one action Example: searching and replacing :1,$s/insure/ensure/g 90 CTEC 110 Chapter 3 (40 slides)

89 Saving a File and Exiting vi
To save file without exiting, use :w To save and exit, use :wq, :x, ZZ (Do this in command mode) 91 CTEC 110 Chapter 3 (40 slides)

90 Adding Text from Another File
To copy entire contents of one file into another file: Use vi to edit the file you would like to copy into Use the command :r filename filename is the name of the file that contains the information you want to copy 92 CTEC 110 Chapter 3 (40 slides)

91 Leaving vi Temporarily
To launch a shell or execute other commands from within vi, use :! Example: :!cal To run several command-line commands in a different shell without closing vi session Use Ctrl+z to display the command line Type fg to go back to vi 93 CTEC 110 Chapter 3 (40 slides)

92 Leaving vi Temporarily (continued)
Chapter 3 (40 slides) CTEC 110 94

93 Changing Your Display While Editing
To turn on line numbering :set number To delete lines 4 through 6 (ex mode) :4,6d 95 CTEC 110 Chapter 3 (40 slides)

94 Copying or Cutting and Pasting
The command yy copies (yanks) a specified number of lines To cut the lines, use dd Lines are placed in clipboard Use p to paste the clipboard contents 96 CTEC 110 Chapter 3 (40 slides)

95 Printing Text Files To print a file, use the lpr (line print) shell command Example: :!lpr -P lp2 accounts 97 CTEC 110 Chapter 3 (40 slides)

96 Canceling an Editing Session
Canceling an editing session will discard all the changes you have made Or, save changes you made since last using :w Saves file without exiting vi 98 CTEC 110 Chapter 3 (40 slides)

97 Getting Help in vi Use the help command Other alternatives: :help
man vi From the command line :!man vi From vi (command mode) 99 CTEC 110 Chapter 3 (40 slides)

98 Using the Emacs Editor Emacs is a popular UNIX/Linux text editor
Not modal More complex than vi More consistent than vi Sophisticated macro language Macro: set of commands that automates a complex task Uses: read mail, edit contents of directories, etc. Powerful command syntax Extensible 100 CTEC 110 Chapter 3 (40 slides)

99 Using the Emacs Editor (continued)
Chapter 3 (40 slides) CTEC 110 101

100 Using the Emacs Editor (continued)
Chapter 3 (40 slides) CTEC 110 102

101 Creating a New File in Emacs
Chapter 3 (40 slides) CTEC 110 103

102 Navigating in Emacs To create a new file: emacs filename
To navigate in the file, use the cursor movement keys or Ctrl/Alt key combinations Example: Alt+f To save your work: Use File menu Use the save icon Press Ctrl+x, Ctrl+s To exit: use menu, icon, or Ctrl+x, Ctrl+c 104 CTEC 110 Chapter 3 (40 slides)

103 Deleting Information Del or Backspace keys delete individual characters Ctrl+k deletes to the end of a line To undo a deletion, use Ctrl+x, u Repeatedly undoes each deletion 105 CTEC 110 Chapter 3 (40 slides)

104 Copying, Cutting, and Pasting Text
To Copy-Paste or Cut-Paste: Mark the text Position cursor at the beginning, and Ctrl+Spacebar Navigate to the end of the text you want to include: Alt+w copies the text Ctrl+w cuts the text To paste, move to where you want to place the text Ctrl+y (the yank command) 106 CTEC 110 Chapter 3 (40 slides)

105 Searching in Emacs One way to search in Emacs is to:
Press Ctrl+s Entering string to find (on status line) Pressing Ctrl+s repeatedly to find each occurrence Use Ctrl+r to search backward Other alternatives: Use search forward for a string icon On the menu: Edit  Search  Search 107 CTEC 110 Chapter 3 (40 slides)

106 Reformatting a File Alt+q turns on word wrap feature
Lines automatically wrap around from one line to the next 108 CTEC 110 Chapter 3 (40 slides)

107 Getting Help in Emacs Emacs comes with extensive documentation and a tutorial Tutorial is useful for getting up to speed quickly Click Help menu  Emacs Tutorial Or (in most versions), type Ctrl+h and then type t To view general Emacs documentation: Ctrl+h (press one or two times) Or, man emacs at command line 109 CTEC 110 Chapter 3 (40 slides)

108 Summary Bytes: computer characters (a series of bits) stored using numeric codes The vi editor is popular among UNIX/Linux users Three modes: insert (i), command (Esc), and ex (Esc :) With vi, you edit a copy of the file placed in memory File is not altered until you save it on disk Emacs is a popular alternative to vi Supports powerful command syntax and is extensible Insert text simply by typing Sophisticated macro language 110 CTEC 110 Chapter 3 (40 slides) 110

109 Command Summary Chapter 3 (40 slides) CTEC 110 111

110 Command Summary (continued)
Chapter 3 (40 slides) CTEC 110 112

111 Chapter 3 Unix Exercises
Work through Hands-on Projects at end of chapter 3 Canvas: Review Questions (Do not do questions 22,23,24 and 25) Read chapter 4 before next class session Quiz 3 Unix… 113 CTEC 110 Chapter 3 (40 slides)

112 UNIX/Linux File Processing
Chapter Four UNIX/Linux File Processing Guide To UNIX Using Linux Fourth Edition 114 CTEC 110 Chapter 4 (27 Slides)

113 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 115 CTEC 110 Chapter 4 (27 Slides)

114 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 116 CTEC 110 Chapter 4 (27 Slides)

115 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 117 CTEC 110 Chapter 4 (27 Slides)

116 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 118 CTEC 110 Chapter 4 (27 Slides)

117 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 119 CTEC 110 Chapter 4 (27 Slides)

118 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 120 CTEC 110 Chapter 4 (27 Slides)

119 121 CTEC 110 Chapter 4 (27 Slides)

120 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) 122 CTEC 110 Chapter 4 (27 Slides)

121 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 123 CTEC 110 Chapter 4 (27 Slides)

122 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 124 CTEC 110 Chapter 4 (27 Slides)

123 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 125 CTEC 110 Chapter 4 (27 Slides)

124 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 126 CTEC 110 Chapter 4 (27 Slides)

125 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 127 CTEC 110 Chapter 4 (27 Slides)

126 The paste command joins text of different files in side by side fashion
Chapter 4 (27 Slides) CTEC 110 128

127 Extracting fields of a file using output redirection: the cut command removes specific columns or fields from a file Chapter 4 (27 Slides) CTEC 110 129

128 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 130 CTEC 110 Chapter 4 (27 Slides)

129 131 CTEC 110 Chapter 4 (27 Slides)

130 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 132 CTEC 110 Chapter 4 (27 Slides)

131 Chapter 4 (27 Slides) CTEC 110 133

132 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 134 CTEC 110 Chapter 4 (27 Slides)

133 A Brief Introduction to the Awk 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 135 CTEC 110 Chapter 4 (27 Slides)

134 A Brief Introduction to the Awk 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 136 CTEC 110 Chapter 4 (27 Slides)

135 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) 137 CTEC 110 Chapter 4 (27 Slides)

136 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 138 CTEC 110 Chapter 4 (27 Slides)

137 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 139 CTEC 110 Chapter 4 (27 Slides)

138 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… 140 CTEC 110 Chapter 4 (27 Slides)

139 Advanced File Processing
Chapter Five Advanced File Processing Guide To UNIX Using Linux Fourth Edition 141 CTEC 110 Chapter 5 Unix (34 slides)

140 Objectives Use the pipe operator to redirect the output of one command to another command Use the grep command to search for a specified pattern in a file Use the uniq command to remove duplicate lines from a file Use the comm and diff commands to compare two files Use the wc command to count words, characters and lines in a file 142 CTEC 110 Chapter 5 Unix (34 slides)

141 Objectives (continued)
Use manipulation and transformation commands, which include sed, tr, and pr Design a new file-processing application by creating, testing, and running shell scripts 143 CTEC 110 Chapter 5 Unix (34 slides)

142 Advancing Your File-Processing Skills
Selection commands focus on extracting specific information from files 144 CTEC 110 Chapter 5 Unix (34 slides)

143 Advancing Your File-Processing Skills (continued)
Manipulation and transformation commands alter and transform extracted information into useful and appealing formats 145 CTEC 110 Chapter 5 Unix (34 slides)

144 Advancing Your File-Processing Skills (continued)
146 CTEC 110 Chapter 5 Unix (34 slides)

145 Using the Selection Commands
Using the Pipe Operator – The pipe operator (|) redirects the output of one command to the input of another An example would be to redirect the output of the ls command to the more command The pipe operator can connect several commands on the same command line 147 CTEC 110 Chapter 5 Unix (34 slides)

146 Using the Pipe Operator
Using pipe operators and connecting commands is useful when viewing directory information 148 CTEC 110 Chapter 5 Unix (34 slides)

147 Using the grep Command Used to search for a specific pattern in a file, such as a word or phrase grep’s options and wildcard support allow for powerful search operations You can increase grep’s usefulness by combining with other commands, such as head or tail 149 CTEC 110 Chapter 5 Unix (34 slides)

148 Using the uniq Command Removes duplicate lines from a file
Compares only consecutive lines, therefore uniq requires sorted input uniq has an option that allows you to generate output that contains a copy of each line that has a duplicate 150 CTEC 110 Chapter 5 Unix (34 slides)

149 Using the uniq Command (continued)
151 CTEC 110 Chapter 5 Unix (34 slides)

150 Using the uniq Command (continued)
152 CTEC 110 Chapter 5 Unix (34 slides)

151 Using the comm Command Column one contains lines found only in file1
Used to identify duplicate lines in sorted files Unlike uniq, it does not remove duplicates, and it works with two files rather than one It compares lines common to file1 and file2, and produces three column output Column one contains lines found only in file1 Column two contains lines found only in file2 Column three contains lines found in both files 153 CTEC 110 Chapter 5 Unix (34 slides)

152 Using the diff Command Attempts to determine the minimal changes needed to convert file1 to file2 The output displays the line(s) that differ Codes in the output indicate that in order for the files to match, specific lines must be added or deleted 154 CTEC 110 Chapter 5 Unix (34 slides)

153 Using the wc Command Used to count the number of lines, words, and bytes or characters in text files You may specify all three options in one issuance of the command If you don’t specify any options, you see counts of lines, words, and characters (in that order) 155 CTEC 110 Chapter 5 Unix (34 slides)

154 Using the wc Command (continued)
The options for the wc command: –l for lines –w for words –c for characters 156 CTEC 110 Chapter 5 Unix (34 slides)

155 Using Manipulation and Transformation Commands
These commands are: sed, tr, pr Used to edit and transform the appearance of data before it is displayed or printed 157 CTEC 110 Chapter 5 Unix (34 slides)

156 Introducing the sed Command
sed is a UNIX/Linux editor that allows you to make global changes to large files Minimum requirements are an input file and a command that lets sed know what actions to apply to the file sed commands have two general forms Specify an editing command on the command line Specify a script file containing sed commands 158 CTEC 110 Chapter 5 Unix (34 slides)

157 Translating Characters Using the tr Command
tr copies data from the standard input to the standard output, substituting or deleting characters specified by options and patterns The patterns are strings and the strings are sets of characters A popular use of tr is converting lowercase characters to uppercase 159 CTEC 110 Chapter 5 Unix (34 slides)

158 Using the pr Command to Format Your Output
pr prints specified files on the standard output in paginated form By default, pr formats the specified files into single- column pages of 66 lines Each page has a five-line header containing the file name, its latest modification date, and current page, and a five-line trailer consisting of blank lines 160 CTEC 110 Chapter 5 Unix (34 slides)

159 Designing a New File-Processing Application
The most important phase in developing a new application is the design The design defines the information an application needs to produce The design also defines how to organize this information into files, records, and fields, which are called logical structures 161 CTEC 110 Chapter 5 Unix (34 slides)

160 Designing Records The first task is to define the fields in the records and produce a record layout A record layout identifies each field by name and data type (numeric or nonnumeric) Design the file record to store only those fields relevant to the record’s primary purpose 162 CTEC 110 Chapter 5 Unix (34 slides)

161 Linking Files with Keys
Multiple files are joined by a key: a common field that each of the linked files share Another important task in the design phase is to plan a way to join the files The flexibility to gather information from multiple files comprised of simple, short records is the essence of a relational database system 163 CTEC 110 Chapter 5 Unix (34 slides)

162 164 CTEC 110 Chapter 5 Unix (34 slides)

163 Creating the Programmer and Project Files
With the basic design complete, you now implement your application design UNIX/Linux file processing predominantly uses flat files Working with these files is easy, because you can create and manipulate them with text editors like vi and Emacs 165 CTEC 110 Chapter 5 Unix (34 slides)

164 Creating the Programmer and Project Files (continued)
166 CTEC 110 Chapter 5 Unix (34 slides)

165 Formatting Output Awk provides a shortcut to other UNIX/Linux commands
The awk command is used to prepare formatted output For the purposes of developing a new file- processing application, we will focus primarily on the printf action of the awk command Awk provides a shortcut to other UNIX/Linux commands 167 CTEC 110 Chapter 5 Unix (34 slides)

166 Using a Shell Script to Implement the Application
Shell scripts should contain: The commands to execute Comments to identify and explain the script so that users or programmers other than the author can understand how it works Use the pound (#) character to mark comments in a script file 168 CTEC 110 Chapter 5 Unix (34 slides)

167 Running a Shell Script You can run a shell script in virtually any shell that you have on your system The Bash shell accepts more variations in command structures that other shells Run the script by typing sh followed by the name of the script, or make the script executable and type ./ prior to the script name 169 CTEC 110 Chapter 5 Unix (34 slides)

168 Putting it All Together to Produce the Report
An effective way to develop applications is to combine many small scripts in a larger script file Have the last script added to the larger script print a report indicating script functions and results 170 CTEC 110 Chapter 5 Unix (34 slides)

169 Chapter Summary UNIX/Linux file-processing commands are (1) selection and (2) manipulation and transformation commands uniq removes duplicate lines from a sorted file comm compares lines common to file1 and file2 diff tries to determine the minimal set of changes needed to convert file1 into file2 171 CTEC 110 Chapter 5 Unix (34 slides)

170 Chapter Summary (continued)
tr copies data read from the standard input to the standard output, substituting or deleting characters specified sed is a file editor designed to make global changes to large files pr prints the standard output in pages 172 CTEC 110 Chapter 5 Unix (34 slides)

171 Chapter Summary (continued)
The design of a file-processing application reflects what the application needs to produce Use record layout to identify each field by name and data type Shell scripts should contain commands to execute programs and comments to identify and explain the programs 173 CTEC 110 Chapter 5 Unix (34 slides)

172 Chapter 5 Unix Exercises
Work through Hands-on Projects at end of chapter 5 Canvas: Review Questions 5 (Do not do questions 22,23,24 and 25) Quiz 5 Unix… 174 CTEC 110 Chapter 5 Unix (34 slides)


Download ppt "The Essence of UNIX and Linux"

Similar presentations


Ads by Google