0% found this document useful (0 votes)
41 views30 pages

Eckert5e ch03

The document discusses Linux file systems and file management. It covers the Linux directory structure including the root directory and absolute vs relative paths. It describes different file types like text, binary, and special files. It explains how to view files and directories using commands like ls, cat, more, less and wildcards. It also discusses editing text files using vi and searching files using grep.

Uploaded by

Stephen Efange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views30 pages

Eckert5e ch03

The document discusses Linux file systems and file management. It covers the Linux directory structure including the root directory and absolute vs relative paths. It describes different file types like text, binary, and special files. It explains how to view files and directories using commands like ls, cat, more, less and wildcards. It also discusses editing text files using vi and searching files using grep.

Uploaded by

Stephen Efange
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 30

Chapter 3

Exploring Linux Filesystems

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. M
ay not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Objectives
• After completing this chapter, you will be able to:
• 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
• 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

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The Linux Directory Structure (1 of 3)
• Directory
• Used to organize other files into a logical tree structure
• Stored in a filesystem of a specific partition in the hard disk or SSD
• Absolute pathname
• Pathname from the root directory to a certain file or directory
• Root
• Top level directory
• Referred to using /root

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The Linux Directory Structure (2 of 3)

Figure 3-1: The Windows filesystem structure

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The Linux Directory Structure (3 of 3)

Figure 3-2: The Linux filesystem structure

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Changing Directories (1 of 2)
• Home directory
• Unique to each user account
• The ~ metacharacter can be used to refer to home directory
• Print working directory (pwd) command
• Displays current directory in the directory tree
• Change directory (cd) command
• Change the current directory
• Relative pathname
• Pathname of target file or directory relative to current directory

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Changing Directories (2 of 2)
• Parent directory
• Directory one step closer to the root of the tree
• Referred to by two dots (..)
• Subdirectory
• Directory residing within another directory
• Tab-completion
• Pressing the Tab key fills in remaining characters
• BASH shell feature
• Alerts user if there is more than one possible match

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Viewing Files and Directories
• Point of a directory structure
• Organize files into an easy-to-use format
• This sections covers various types of files and filenames
• As well as different commands used to select filenames for viewing

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
File Types
• Text files: contain configuration information
• Binary data files: store information such as common functions
and graphics
• Linked files: files that have an association with one another
• Special device files: files that represent different devices on the
system
• Named pipe files: identify channels that pass information from
one process in memory to another
• Socket files: allow a process on another computer to write to a file
on the local computer while another process reads from that file
Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Filenames
• Filename
• Identifier given to a file
• Up to 255 characters (rarely longer than 20 characters)
• Alphanumeric characters, underscore (_), dash (-), and period (.)
• Filename extensions
• Identifiers following a period (.) at end of filename
• Indicate file type
• Most files on Linux do not have filename extensions

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Listing Files (1 of 3)
• 1s command: displays files in a directory
• 1s –F command appends a special character at the end of each filename
displayed to indicate the type of file
• 1s –l command can be used to provide a long listing for each file in a
certain directory

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Listing Files (2 of 3)
• File components
• File type character
• List of permissions on the file
• Hard link count
• Owner of the file
• Group owner of the file
• File size
• Most recent modification time
• Filename

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Listing Files (3 of 3)
• File command: displays file type of any file
• Argument indicates what file or files to analyze
• Identifies between different types of executable files
• Identifies empty files
• Hidden files: files not normally displayed to user
• Configuration files often hidden
• Filenames start with a dot (.)
• ls –a command: displays hidden files

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Wildcard Metacharacters (1 of 2)
• Simplify commands specifying more than one filename on the
command line
• Can match the entire filename or portions of filenames
• Can be used with most Linux filesystem commands

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Wildcard Metacharacters (2 of 2)

Table 3-3: Wildcard metacharacter

Metacharacter Description

* Matches 0 or more characters in a filename

? Matches 1 character in a filename

[aegh] Matches 1 character in a filename—provided this character


is either an a, e, g, or h
[a-e] Matches 1 character in a filename—provided this character
is either an a, b, c, d, or e
[!a-e] Matches 1 character in a filename—provided this character
is NOT an a, b, c, d, or e

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Displaying the Contents of Text Files (1 of 2)
• Concatenation: view an entire text file on the terminal screen
• The cat command: displays contents of a text file to the screen
• The -n option: displays line number of each line in the file
• Log files: contain records of events
• Most recent events are appended to end of the file
• The tac command: displays contents of a text file in reverse order
• Head command: displays the first ten lines of a file
• Tail command: displays the last ten lines of a file

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Displaying the Contents of Text Files (2 of 2)
• Large text files can not be viewed using the cat command
• Screen will only fit a portion of the file
• The more command: displays text files page-by-page
• The less command: same as more command, but can also use arrow
keys
• The more and less commands can be used with output of other
commands

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Displaying the Contents of Binary Files
• To view contents of binary files, you typically use the program that
created the file
• The strings command: searches for and displays text characters
in a binary file
• Might indicate purpose of binary file
• The od command: displays contents of file in octal format
(numeric base 8 format)
• The -x option displays contents of the file in hexadecimal format (numeric
base 16 format)

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Searching for Text Within Files
• Text tools
• Commands that search for and manipulate text
• Such as database information
• Regular expressions (regexp)
• Text wildcards that ease the search for specific text
• Recognized by several text tools and programming languages

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Regular Expressions (1 of 2)
• Different from wildcard metacharacters
• Wildcard metacharacters are interpreted by the shell, whereas regular
expressions are interpreted by a text tool program
• Wildcard metacharacters match characters in filenames (or directory
names) on a Linux filesystem, whereas regular expressions match
characters within text files on a Linux filesystem
• Wildcard metacharacters typically have different definitions than regular
expression metacharacters
• More regular expression metacharacters are available than wildcard
metacharacters

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Regular Expressions (2 of 2)
• Regular expressions are divided into two different categories
• Common regular expressions: available to most text tools
• Extended regular expressions: less common and available in only certain
text tools

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The grep Command (1 of 2)
• The global regular expression print (grep) command: displays
lines in a text file that match common regular expressions
• The egrep command: displays lines in a text file that match
extended regular expressions
• The fgrep command: does not interpret any regular expressions
and returns results much faster

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The grep Command (2 of 2)
• Requires two arguments
• Text to search for
• Files to search
• Case sensitive
• For case-insensitive search, use –i option
• Matches patterns of text
• Unable to discern words or phrases unless they are specified

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Editing Text Files
• Most system configuration is stored in text files
• As is commonly accessed information such as e-mail and program source
code
• Most Linux distributions come with several text editors
• Editors that can be used on the command line
• Editors that can be used in a GUI environment

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The vi Editor (1 of 2)
• One of the oldest and most popular text editors for UNIX OSs
• Linux equivalent of vi: vim
• Standard on most Linux distributions
• Advantage is portability, not usability
• Used on Unix and Linux
• The vi editor supports regular expressions
• Can perform over 1000 different functions for the user

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
The vi Editor (2 of 2)
• The vi editor is called a bi-modal editor
• Command mode: performs text editing tasks not related to inserting text
• Such as deleting text, copying text, saving changes to a file, and exiting the vi editor
• Insert mode: inserts text, but nothing else
• Press the Esc key to return to command mode
• User environment is customizable
• Through settings that can be altered at the : prompt

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Other Common Text Editors (1 of 2)
• GNU Emacs (Editor MACroS) editor: offers comparable
functionality to vi
• Nano editor: text editor that uses Ctrl key combinations for
performing functions
• The gedit editor: graphical text editor functional in a GUI
environment

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Other Common Text Editors (2 of 2)

Figure 3-3: The gedit text editor

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Summary (1 of 2)
• The Linux filesystem is arranged hierarchically
• Series of directories store files
• The ls command is used to view filenames
• Wide range of options to modify views
• Wildcard metacharacters are special keyboard characters
• Simplify selection of several files when using common Linux file
commands
• Text files are the most common file type
• Contents can be viewed by several utilities: head, tail, cat, tac, more, and
less

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Summary (2 of 2)
• Regular expression metacharacters can be used to specify
certain patterns of text
• Used with certain programming languages and text tool utilities such as
grep
• Although many command-line and graphical text editors exist, vi
(vim) is a powerful, bimodal text editor
• Standard on most UNIX and Linux systems

Eckert, Linux+ and LPIC-1 Guide to Linux Certification, 5th Edition. © 2019 Cengage. All Rights Reserved. May
not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

You might also like