Title: Linux Guide to Linux Certification, Second Edition
1Linux Guide to Linux Certification, Second
Edition
- Chapter 4
- Exploring Linux Filesystems
2Objectives
- 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
3Objectives (continued)
- Display the contents of text files and binary
files - Search text files for regular expressions using
grep - Identify common text editors used today
- Use the vi editor to manipulate text files
4The Linux Directory Structure
- Directory Used to organize other files into a
logical tree structure - Absolute pathname Pathname from the root
directory to a certain file or directory - Root The top level directory
- referred to using the / character
5The Linux Directory Structure (continued)
Figure 4-1 The Windows filesystem structure
Figure 4-2 The Linux filesystem structure
6Changing Directories
- Home directory Unique to each user
- pwd (print working directory) command Displays
current directory in the directory tree - cd (change directory) command Change the current
directory in the directory tree - metacharacter Refers to home directory
- Relative pathname Pathname of file or directory
relative to current directory
7Changing Directories (continued)
- Subdirectory Directory residing within another
directory - Tab-completion Pressing the Tab key fills in
remaining characters of a unique filename or
directory name - BASH shell feature
8Viewing Files and Directories File Types
- Text files Store information in a readable text
format - Binary data files Store information associated
with executable programs - Executable program files
- Directory files
9Viewing 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
10Filenames
- Filename Identifier given to a file
- Filename extensions Identifiers following a dot
(.) at end of filename - Denote file type
- Most files on Linux do not have file extensions
11Filenames (continued)
Table 4-1 Common filename extensions
12Filenames (continued)
Table 4-1 (continued) Common filename extensions
13Listing Files
- ls command List the files in a directory
- May pass an argument indicating the directory to
be listed - F switch Argument to list file types
- l switch Argument to list long file listings
- Alias Shortcut for a command
- ll command Alias for ls -l
- File command Displays file type of any file
14Listing Files (continued)
- Hidden files Files not normally displayed to
user - Filenames start with a dot (.)
- Configuration files often hidden
- ls a command Displays hidden files
15Listing Files (continued)
Table 4-2 Common options to the ls command
16Listing Files (continued)
Table 4-2 (continued) Common options to the ls
command
17Wildcard Metacharacters
- Wildcard metacharacter Used to simplify commands
specifying multiple filenames - Can be used with most Linux filesystem commands
18Wildcard Metacharacters (continued)
Table 4-3 Wildcard metacharacters
19Displaying Content of Text Files
- Concatenation Joining text together
- cat command Displays (concatenates) contents of
a text file to the screen - -n switch Displays line number and contents
- Log files Contain records of past system events
- New events appended to end
- tac command Displays files in reverse order
- head command View first few lines of a file
20Displaying Content of Text Files (continued)
- tail command View last few lines of a file
- Can also specify what line number to start at
- more command Displays text files page-by-page
- Space key goes to next page
- Enter key goes to next line
- less command Same as more command, but can also
use cursor to scroll
21Displaying Content of Text Files (continued)
- more and less can be used with output of other
commands - If output is too large to fit on terminal screen,
use metacharacter - e.g., ls -l more
22Displaying the Contents of Binary Files
- Typically use program that created the file
- strings command Searches for and displays text
characters in a binary file - Might indicate purpose of binary file
- od command Displays contents of file in octal
format (numeric base 8 format)
23Searching for Text Within Files
- Text tools Search for and manipulate text
- Regular expressions (regexp) Text wildcards that
assist search for specific text - Match patterns of text
- Used by many text tools and programming languages
- Including grep, emacs, C, PERL, and many more
24Regular 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 - More regexps than wildcard metacharacters
- Common and extended regexps
25Regular Expressions (continued)
Table 4-4 Regular expressions
26Regular Expressions (continued)
Table 4-4 (continued) Regular expressions
27The grep Command
- grep (global regular expression print) command
Displays lines in a text file matching a given
regexp - egrep command Displays lines of text that match
extended regexps - fgrep command Does not interpret any regular
expressions - Returns results much faster than egrep
- grep requires two arguments
- Text to search for and files to search
28Editing 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
29Editing Text Files The vi Editor (continued)
Table 4-5 Common keyboard keys used to change to
and from insert mode
30Editing Text Files The vi Editor (continued)
Table 4-6 Key combinations commonly used in
command mode
31Editing Text Files The vi Editor (continued)
Table 4-6 (continued) Key combinations commonly
used in command mode
32Editing Text Files The vi Editor (continued)
Table 4-6 (continued) Key combinations commonly
used in command mode
33Editing Text Files The vi Editor (continued)
Table 4-7 Key combinations commonly used at the
command mode prompt
34Other Common Text Editors
- Mcedit editor (Midnight Commander Editor)
Easy-to-use text editor - Supports regexp
- Supports use of mouse for highlighting text
- Emacs (Editor MACroS) editor Comparable
functionality to vi - Ctrl key combinations to perform special
functions - Supports LISP (LISt Processing) artificial
intelligence programming language
35Other Common Text Editors (continued)
Table 4-8 Keyboard functions commonly used in
the GNU emacs editor
36Other Common Text Editors (continued)
- Emacs editor is not easy to use
- Must memorize key combinations
- Xemacs editor Version of Emacs for KDE or GNOME
GUI environments - Easier to use than emacs
- Not available with every distribution
37Other Common Text Editors (continued)
Figure 4-3 The xemacs text editor
38Other Common Text Editors (continued)
- Graphical text editors available with most Linux
distributions - nedit editor
- gedit editor Distributed with GNOME environment
- kedit editor Distributed with KDE environment
- gedit and kedit offer more functionality than
nedit
39Other Common Text Editors (continued)
Figure 4-4 The nedit text editor
40Other Common Text Editors (continued)
Figure 4-5 The gedit text editor
41Other Common Text Editors (continued)
Figure 4-6 The kedit text editor
42Summary
- The Linux filesystem is arranged hierarchically
using a series of directories to store files - Location of these directories and files can be
described using absolute or relative pathnames - Accommodates many types of files text files,
binary data, executable programs, directories,
linked files, and special device files - The ls command is used to view filenames
- Wide range of options
- Wildcard metacharacters can simplify selection of
several files when using common Linux file
commands
43Summary (continued)
- 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 - Regular expression metacharacters can be used to
specify certain patterns of text when 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