guide to linux installation and administration, 2e1 chapter 6 using the shell and text files
TRANSCRIPT
![Page 1: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/1.jpg)
Guide to Linux Installation and Administration, 2e 1
Chapter 6
Using the Shell and Text Files
![Page 2: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/2.jpg)
Guide to Linux Installation and Administration, 2e 2
Objectives
In this chapter, you will:
• Describe how a Linux shell operates
• Customize your shell environment
• Use common text editors to create or modify text files
• Describe popular text-processing methods and tools used on Linux
![Page 3: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/3.jpg)
Guide to Linux Installation and Administration, 2e 3
Understanding the Shell
• Command interpreter: program that accepts input from the keyboard and launches commands or otherwise controls the computer system
• Linux command interpreter is called the shell
• The shell is only loaded when a user logs in at a text mode login prompt
• Different types of shells are available for Linux
Valued Gateway Client:
Valued Gateway Client:
![Page 4: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/4.jpg)
Guide to Linux Installation and Administration, 2e 4
The Shell Prompt
• Shell prompt: set of words or characters indicating that the shell is ready for commands
• The default shell prompt includes four components:– The user account name
– The hostname
– The last part of the full directory path
– A prompt character
Valued Gateway Client:
Valued Gateway Client:
![Page 5: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/5.jpg)
Guide to Linux Installation and Administration, 2e 5
A Standard Shell Prompt
![Page 6: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/6.jpg)
Guide to Linux Installation and Administration, 2e 6
The Functions of a Shell
• A shell’s primary purpose is to launch programs• A Linux shell gives users the ability to write
scripts that the shell can execute• The shell has many built-in features to work with
files and commands on a Linux system
Valued Gateway Client:
Valued Gateway Client:
![Page 7: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/7.jpg)
Guide to Linux Installation and Administration, 2e 7
Different Types of Shells
![Page 8: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/8.jpg)
Guide to Linux Installation and Administration, 2e 8
Different Types of Shells
![Page 9: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/9.jpg)
Guide to Linux Installation and Administration, 2e 9
Entering Commands
• Modern shells include features designed to simplify the process of entering commands and command parameters:– Tab completion
– History feature
Valued Gateway Client:
Valued Gateway Client:
![Page 10: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/10.jpg)
Guide to Linux Installation and Administration, 2e 10
Using Tab Completion
• Tab completion is a shell feature that lets you enter part of a file or directory name, press the Tab key, and have the shell fill in the remainder of the name
• Using tab completion makes it easier to enter long or complex directory paths and filenames
Valued Gateway Client:
Valued Gateway Client:
![Page 11: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/11.jpg)
Guide to Linux Installation and Administration, 2e 11
Using the History Feature
• Command history: records each command that you enter at the shell prompt
• History list: recently entered commands• To locate a previously executed command
– Use the history number
– Use the beginning of a command
– Search the history list
Valued Gateway Client:
Valued Gateway Client:
![Page 12: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/12.jpg)
Guide to Linux Installation and Administration, 2e 12
The Shell Start-up Process
• The profile scripts are executed when a user logs into a Linux system
• Additional scripts are executed when a user starts a shell
• The /etc/profile script contains configuration information that applies to every user on the system
Valued Gateway Client:
Valued Gateway Client:
![Page 13: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/13.jpg)
Guide to Linux Installation and Administration, 2e 13
A Typical Start-up Script
![Page 14: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/14.jpg)
Guide to Linux Installation and Administration, 2e 14
Customizing the Shell
• You can customize the Linux environment with the following methods:– Use aliases
– Use symbolic links
– Use environment variables
Valued Gateway Client:
Valued Gateway Client:
![Page 15: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/15.jpg)
Guide to Linux Installation and Administration, 2e 15
Using Aliases
• Alias: string of characters that is substituted for another string of characters at the shell prompt
• The alias command lets you define an alias for text you enter at a shell prompt
• General format of the alias command:
alias<string entered>=<string substituted by the shell>
Valued Gateway Client:
Valued Gateway Client:
![Page 16: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/16.jpg)
Guide to Linux Installation and Administration, 2e 16
Symbolic Links
• Symbolic link– File that refers to another file or directory, rather
than containing data itself
– Used when the same data must be accessed from two locations in the directory structure, or by two different names
– Commonly used in directories such as /lib and /usr/lib
• To create a symbolic link, use the ln command with the -s option
Valued Gateway Client:
Valued Gateway Client:
![Page 17: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/17.jpg)
Guide to Linux Installation and Administration, 2e 17
A Symbolic Link
![Page 18: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/18.jpg)
Guide to Linux Installation and Administration, 2e 18
Viewing a Symbolic Link
![Page 19: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/19.jpg)
Guide to Linux Installation and Administration, 2e 19
Environment Variables
• Environment variables are settings, or values, available to any program launched by a user
• Each environment variable is assigned a value• Set command: displays a list of all environment
variables defined in your current environment• To see the value of an environment variable,
execute echo followed by the environment variable name preceded by a dollar sign
• The export command makes an environment variable available to other programs launched from that environment
Valued Gateway Client:
Valued Gateway Client:
![Page 20: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/20.jpg)
Guide to Linux Installation and Administration, 2e 20
Using Text Editors
• Linux supports numerous text editors• Linux system administrator can modify
configuration files using any text editor• Files that use a markup language can be created
in any text editor• You can filter text files within some text editors
Valued Gateway Client:
Valued Gateway Client:
![Page 21: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/21.jpg)
Guide to Linux Installation and Administration, 2e 21
The Variety of Linux Text Editors
• Graphical text editors are included on modern Linux desktops, such as– gedit in Gnome
– kedit and kate in KDE
• Widely used text-mode editors:– vi
– emacs
– pico
– joe
Valued Gateway Client:
Valued Gateway Client:
![Page 22: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/22.jpg)
Guide to Linux Installation and Administration, 2e 22
The pico Text Editor
![Page 23: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/23.jpg)
Guide to Linux Installation and Administration, 2e 23
Using the vi Editor
• vi is a modal editor – keystrokes are interpreted differently depending on the mode you are working in
• vi has several modes:– Command mode
– Insert mode
– Replace mode
Valued Gateway Client:
Valued Gateway Client:
![Page 24: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/24.jpg)
Guide to Linux Installation and Administration, 2e 24
Using the vi Editor
![Page 25: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/25.jpg)
Guide to Linux Installation and Administration, 2e 25
vi Commands to Enter Insert or Replace Mode
![Page 26: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/26.jpg)
Guide to Linux Installation and Administration, 2e 26
Additional vi Commands
![Page 27: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/27.jpg)
Guide to Linux Installation and Administration, 2e 27
Text Processing
• There are two methods to create formatted documents:– Graphical, or WYSIWYG (what-you-see-is-what-
you-get)
– Rely on markup languages to define special codes that format documents
Valued Gateway Client:
Valued Gateway Client:
![Page 28: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/28.jpg)
Guide to Linux Installation and Administration, 2e 28
Markup Languages
• Widely used markup languages in the Unix and Linux world:– HTML (hypertext markup language)
– TeX – a document-processing system with two popular versions: LaTeX and TeTeX
– roff codes for online documents
Valued Gateway Client:
Valued Gateway Client:
![Page 29: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/29.jpg)
Guide to Linux Installation and Administration, 2e 29
An HTML Document in vi
![Page 30: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/30.jpg)
Guide to Linux Installation and Administration, 2e 30
Controlling Fonts
• The X Window System is installed with many different fonts
• xfontsel graphical program is used to review and select fonts
• Both Gnome and KDE provide a standard font selection dialog box
• Fonts are managed in X using the xfs font server• New fonts can be added to the Linux system any
time
Valued Gateway Client:
Valued Gateway Client:
![Page 31: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/31.jpg)
Guide to Linux Installation and Administration, 2e 31
The xfontsel Program
![Page 32: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/32.jpg)
Guide to Linux Installation and Administration, 2e 32
The Font Selector Dialog Box in Gnome
![Page 33: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/33.jpg)
Guide to Linux Installation and Administration, 2e 33
Manipulating Text Files
• Filtering is the process of adding, removing, or altering data in the text file based on complex rules or patterns
• sort command: sorts all of the lines in a text file, writing them out in alphabetical order
• sed command: processes each line in a text file according to a series of command-line options
• awk and perl programming languages can be used to create scripts for filtering text files
Valued Gateway Client:
Valued Gateway Client:
![Page 34: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/34.jpg)
Guide to Linux Installation and Administration, 2e 34
Linux Text-filtering Commands
![Page 35: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/35.jpg)
Guide to Linux Installation and Administration, 2e 35
Summary
• Linux shell: program that launches other programs and works with files in Linux
• Modern shells include features designed to simplify the process of entering commands - tab completion and history
• Aliases within a shell cause the shell to replace text on a command-line entry with different text before trying to execute the command
• Environment variables store values that any program can access
![Page 36: Guide to Linux Installation and Administration, 2e1 Chapter 6 Using the Shell and Text Files](https://reader036.vdocuments.mx/reader036/viewer/2022081514/56649d755503460f94a5543a/html5/thumbnails/36.jpg)
Guide to Linux Installation and Administration, 2e 36
Summary
• Linux supports text editors, such as vi • Linux programs format text using a WYSIWYG
display or markup languages such as LaTeX and roff use codes
• Fonts are managed in X Windows System using a font server
• Gnome and KDE provide a dialog box to select the font for graphical programs
• Filtering text files can be done within some text editors or using different command-line utilities