Upload
marion-clark
View
216
Download
1
Tags:
Embed Size (px)
Citation preview
Week 3Exploring Linux Filesystems
Objectives
Understand and navigate the Linux directory structure using relative and absolute pathnames
Describe the various types of Linux files View filenames and file types Use shell wildcards to specify multiple
filenames
Linux+ Guide to Linux Certification, 3e 2
Objectives (continued)
Display the contents of text files and binary files
Search text files for regular expressions using grep
Use the vi editor to manipulate text files Identify common alternatives to the vi
text editor used today
Linux+ Guide to Linux Certification, 3e 3
The Linux Directory Structure Directory: Used to organize other files
into a logical tree structureStored in a filesystem of a specific partition
in the hard disk
Absolute pathname: Pathname from the root directory to a certain file or directory
Root: The top level directoryReferred to using the / characterForms root of a hierarchical tree
Linux+ Guide to Linux Certification, 3e 4
The Linux Directory Structure (continued)
Linux+ Guide to Linux Certification, 3e 5
Figure 3-1: The Windows file system structure
The Linux Directory Structure (continued)
Linux+ Guide to Linux Certification, 3e 6
Figure 3-2: The Linux file system structure
Changing Directories Home directory: unique to each user
~ metacharacter used to refer to home directory pwd (print working directory) command:
displays current directory in the directory tree
cd (change directory) command: change the current directory in the directory tree Argument specifies the destination directory
Relative pathname: pathname of file or directory relative to current directory
Linux+ Guide to Linux Certification, 3e 7
Changing Directories (continued) Parent directory: directory one step closer
to the root of the treeReferred to by .. (two dots)
Subdirectory: directory residing within another directory
Tab-completion: pressing the Tab key fills in remaining characters of a unique filename or directory nameBASH shell featureAlerts user if there is more than one possible
match
Linux+ Guide to Linux Certification, 3e 8
Viewing Files and Directories: File Types Text files: store information in a readable
text format, contain configuration information
Binary data files: store information associated with executable programs
Executable program files Directory files: serve as placeholders to
organize other files
Linux+ Guide to Linux Certification, 3e 9
Viewing Files and Directories: File Types (continued) Linked files: associated with another file Special device files: represent system
devices Named pipes: identify channel that
passes information between processes Socket files: allow a process on another
computer to write to a local file
Linux+ Guide to Linux Certification, 3e 10
Filenames Filename: identifier given to a file
Up to 255 charactersCan use alphanumeric characters, dash (-),
underscore (_), and dot (.) Filename extensions: identifiers
following a dot (.) at end of filename Denote file typeMost files on Linux do not have filename
extensions
Linux+ Guide to Linux Certification, 3e 11
Linux+ Guide to Linux Certification, 3e 12
Table 3-1: Common filename extensions
Listing Files
ls command: List the files in a directoryMay pass an argument indicating the
directory to be listed○ –F option: Argument to indicate file types○ –l option: Argument to list long file listings
Linux+ Guide to Linux Certification, 3e 13
Listing Files (continued) Long listing for each file includes eight
componentsFile type characterList of permissions (mode of the file)Hard link countOwnerGroup ownerFile sizeMost recent modification timeFilename
Linux+ Guide to Linux Certification, 3e 14
Listing Files (continued) Alias: shortcut for a command
ll command: Alias for ls -l File command: displays file type of any file
Argument indicates what file or files to analyzeIdentifies between different types of executable
filesIdentifies empty files
Hidden files: files not normally displayed to userConfiguration files often hiddenFilenames start with a dot (.)ls –a command: displays hidden files
Linux+ Guide to Linux Certification, 3e 15
Listing Files (continued)
Linux+ Guide to Linux Certification, 3e 16
Table 3-2: Common options to the ls command
Listing Files (continued)
Linux+ Guide to Linux Certification, 3e 17
Table 3-2 (continued): Common options to the ls command
Wildcard Metacharacters
Wildcard metacharacter: used to simplify commands specifying multiple filenamesCan match the entire filename or portions of
filenamesCan be used with most Linux filesystem
commands
Linux+ Guide to Linux Certification, 3e 18
Wildcard Metacharacters (continued)
Linux+ Guide to Linux Certification, 3e 19
Table 3-3: Wildcard metacharacters
Displaying Content of Text Files Concatenation: joining text together cat command: displays (concatenates)
contents of a text file to the screen-n option: displays line number and contents
Log files: contain records of past system eventsNew events appended to end
tac command: displays contents of a text file in reverse order
Linux+ Guide to Linux Certification, 3e 20
Displaying Content of Text Files (Continued) head command: view first ten lines of a
file tail command: view last ten lines of a file For head and tail commands
Line count includes blank linesCan provide numeric option to specify the
number of lines to be displayed (e.g., head -2 filename)
Linux+ Guide to Linux Certification, 3e 21
Displaying Content of Text Files (continued) Large text files can not be viewed using
the cat command, because the screen will only fit a portion of the file
more command: displays text files page-by-pagePressing Spacebar displays the next pagePressing Enter displays the next line
less command: same as more command, but can also use cursor to scroll
Linux+ Guide to Linux Certification, 3e 22
Displaying Content of Text Files (continued) Users can use keyboard shortcuts to
interact with shell while in more and less commands. e.g., pressing h key gets Help screene.g., pressing q key quits more and less
commands more and less can be used with output of
other commands If output is too large to fit on terminal screen,
use “|” metacharacter and more or less command
e.g., ls -l | more
Linux+ Guide to Linux Certification, 3e 23
Displaying the Contents of Binary Files Typically use program that created the
file strings command: searches for and
displays text characters in a binary fileMight indicate purpose of binary file
od command: displays contents of file in octal format (numeric base 8 format)-x option displays contents of the file in
hexadecimal format (numeric base 16 format)
Linux+ Guide to Linux Certification, 3e 24
Searching for Text Within Files Text tools: commands that search for and
manipulate text Regular expressions (regexp): text
wildcards that ease the search for specific textMatch patterns of text within a text documentUsed by many text tools and programming
languages○ Including grep, emacs, C++, PERL, and many
more
Linux+ Guide to Linux Certification, 3e 25
Regular Expressions Different from wildcard metacharacters
Wildcard metacharacters interpreted by shell; regexps interpreted by text tools
Wildcard metacharacters match characters in filenames; regexps match characters within text files
Wildcard metacharacters have different definitions that regexps
More regexps than wildcard metacharacters Regular expressions are divided into
common regexps and extended regexps
Linux+ Guide to Linux Certification, 3e 26
Linux+ Guide to Linux Certification, 3e 27
Table 3-4: Regular expressions
The grep Command grep (global regular expression print)
command: displays lines in a text file that match common regexps
egrep command: displays lines in a text file that match extended regexpsCan be written as grep -E
fgrep command: does not interpret any regular expressions Returns results much faster than egrepCan be written as grep -F
Linux+ Guide to Linux Certification, 3e 28
The grep Command (continued) grep requires two arguments
Text to search for ○ Can use regular expressions
Files in which to search grep is case sensitive
For case-insensitive search, use –i option grep matches patterns of text, ignoring
division into wordsTo search only for occurrences of a word,
surround it by space characters
Linux+ Guide to Linux Certification, 3e 29
Editing Text Files: The vi Editor One of the oldest and most popular text editors
for UNIX OSs Vim: Linux equivalent of vi
Standard on most Linux distributions Advantage is portability, not usability
Used on Unix and Linux Bi-modal editor (two possible modes):
Command mode: Performs text editing tasks not related to inserting text
Insert mode: Inserts text, but nothing else User environment is customizable
Linux+ Guide to Linux Certification, 3e 30
Editing Text Files: The vi Editor (continued)
Linux+ Guide to Linux Certification, 3e 31
Table 3-5: Common keyboard keys used to change to and from insert mode
Editing Text Files: The vi Editor (continued)
32Linux+ Guide to Linux Certification, 3e
Table 3-6: Key combinations commonly used in command mode
Editing Text Files: The vi Editor (continued)
33Linux+ Guide to Linux Certification, 3e
Table 3-6 (continued): Key combinations commonly used in command mode
Editing Text Files: The vi Editor (continued)
34Linux+ Guide to Linux Certification, 3e
Table 3-6 (continued): Key combinations commonly used in command mode
Editing Text Files: The vi Editor (continued)
Linux+ Guide to Linux Certification, 3e 35
Table 3-7: Key combinations commonly used at the command mode : prompt
Other Common Text Editors Emacs (Editor MACroS) editor: comparable
functionality to viCtrl key combinations to perform special
functions Supports LISP (LISt Processing) artificial
intelligence programming language Emacs editor is not easy to use
Must memorize key combination Emacs can be run in a GUI environment to
get a graphical version of the editorMuch easier to use; icons replace key
combinations
Linux+ Guide to Linux Certification, 3e 36
Other Common Text Editors (continued)
Linux+ Guide to Linux Certification, 3e 37
Table 3-8: Keyboard functions commonly used in the GNU Emacs editor
Other Common Text Editors (continued)
Linux+ Guide to Linux Certification, 3e 38
Figure 3-3: A graphical Emacs session
Other Common Text Editors (continued)
Nano editor: text editor that uses Ctrl key combinations for performing functionsBased on the pine UNIX editorCtrl key combinations listed at the bottom of the
screen
Very basic and easy-to-useUsed by Linux administrators to modify files
when advanced functionality is not needed
Linux+ Guide to Linux Certification, 3e 39
Other Common Text Editors (continued) gedit editor: a graphical text editor
functional in a GUI environmentDoes not have advanced functionality like vi
and EmacsEasiest editor to useFunctionality is analogous to the Windows
Wordpad and Notepad editors
Linux+ Guide to Linux Certification, 3e 40
Other Common Text Editors (continued)
Linux+ Guide to Linux Certification, 3e 41
Figure 3-4: The gedit text editor
Summary The Linux filesystem is arranged
hierarchically using a series of directories to store files
Location of directories and files can be described using absolute or relative pathnames
Linux filesystem can contain many types of filestext files, binary data, executable programs,
directories, linked files, and special device files The ls command is used to view filenames
Wide range of options to modify views
Linux+ Guide to Linux Certification, 3e 42
Summary (continued) Wildcard metacharacters are special
keyboard characterscan simplify selection of several files when
using common Linux file commands Text files are the most common file type
whose contents can be viewed by several utilities, such as head, tail, cat, tac, more, and less
Linux+ Guide to Linux Certification, 3e 43
Summary (continued)
Regular expression metacharacters can be used to specify certain patterns of text used with certain programming languages and
text tool utilities such as grep
vi (vim) is a powerful, bimodal text editor that is standard on most UNIX and Linux systems
Linux+ Guide to Linux Certification, 3e 44