You are on page 1of 56

Exploring Linux filesystems

Unit objectives
 Discuss the directory structure and file
Course ILT

types and use wildcards to specify

multiple file names
 Display the contents of text files and
binary files
 Search text files for regular
expressions and identify common
Topic A
 Topic A: Linux files and directories
 Topic B: Displaying the contents of
Course ILT

 Topic C: Searching and editing text
Course ILT The Linux directory structure
The Linux directory structure
 Directory
– Special file used to organize other files into a
Course ILT

logical structure
 Absolute pathname
– Full pathname to a certain file or directory
starting from the root directory
Home directory
 Home directory
– A directory for users to store personal
Course ILT

files and information

– Each user has a subdirectory
Changing directories
 pwd (print working directory)
– Used to identify the current directory path
Course ILT

 cd (change directory)
– Used to move from one directory to
The ~ metacharacter and relative paths

– Refers to the current user’s home
Course ILT

– Can specify another user’s home
directory by adding the username after ~
 Relative pathname
– Pathname of a target directory relative to
your current location in the tree

 Tab-completion
Course ILT

– Fills in the remaining characters of a

unique filename or directory name when
you press the Tab key
Course ILT Activity A-1

Logging on and navigating the file

File types

 Text files
Course ILT

 Binary data files

 Executable program files
 Directory files
 Linked files
 Special device files
 Named pipes and socket files
 Filename
– User-friendly identifier given to a file
Course ILT

 Filename suffixes
– Identifiers following a dot (.) at the end of
a filename
– Used to denote the type of the file
Course ILT Filename extensions, continued
The ls command
 Used to list the files in a directory
 Most common method for displaying
Course ILT

 Displays all the files in the current
– You can use an argument with ls to list a
directory different from current one
Ls –F file type characters
 @ Linked file
 * Executable file
Course ILT

 / Subdirectory
 = Socket file
 | Named pipe
The file command
 File command
Course ILT

– Displays detailed information about any

– Works with multiple files
– Uses * to include all files in a directory
Hidden files
 Hidden files
– Files that are not normally displayed with
Course ILT

common filesystem commands

– Represent important configuration files or
program directories
Course ILT ls command options

Course ILT ls command options, continued
Course ILT Activity A-2

Examining files and file types

Wildcard metacharacters
 Can simplify more than one filename
to a command
Course ILT

 Interpreted by the shell and can be

used with most filesystem commands
 Matches certain portions of filenames
or an entire filename

Course ILT Wildcard metacharacters, continued
Course ILT Activity A-3

Using wildcard metacharacters

Topic B
 Topic A: Linux files and directories
 Topic B: Displaying the contents of
Course ILT

 Topic C: Searching and editing text
Displaying content of text files
 cat command
– Display the entire contents of a text file to
Course ILT

the screen
 tac command
– Displays a file to the screen beginning
with the last line of the file and ending
with the first line of the file
 head command
– Displays the first 10 lines (including blank
lines) of a text file to the terminal screen
– Can also take a numeric option specifying
a different number of lines to display
Displaying content of text files, continued

 tail command
– By default, displays the last 10 lines
Course ILT

(including blank lines) of a text file to the

terminal screen
– Can also take a numeric option specifying
a different number of lines to display
Other text file viewing commands
 more command
– Displays a text file page-by-page and
Course ILT

line-by-line on the terminal screen

– Gets its name from the pg command
once used on UNIX systems
 less command
– Displays a text file page-by-page on the
terminal screen
– Use the arrow keys to navigate the file
Course ILT Activity B-1

Displaying text file contents

Displaying the contents of binary files

 strings commands
– Linux command used to search for and
Course ILT

display text characters in a binary file

 od command
– Linux command that is used to display
the contents of a file in octal format
(numeric base 8 format)
– Safe to use on binary files and text files
Course ILT Activity B-2

Displaying binary data

Topic C
 Topic A: Linux files and directories
 Topic B: Displaying the contents of
Course ILT

 Topic C: Searching and editing text
Searching for text within files
 Regular expressions (regexp)
– Special metacharacters used to match
Course ILT

patterns of text within text files

– Commonly used by many text tool
commands such as grep
Using regular expressions

 grep
Course ILT

 awk
 sed
 vi
 emacs
 ex
 ed
Regular expressions and wildcards

 Wildcard metacharacters are

Course ILT

interpreted by the shell; regular

expressions are interpreted by a text
tool program
 Regular expressions match
characters within text files; wildcard
metacharacters match characters in
filenames or directory names

Regular expressions and wildcards, continued

 Wildcard metacharacters regular

expressions usually have different
Course ILT

definitions than wildcard

 More metacharacters are available
for regular expressions
 Regular expressions are divided into
two different categories:
– Common
– Extended
Course ILT Regular expressions
The grep command
 grep
– Displays lines in a text file that match a
Course ILT

common regular expression

 egrep
– Displays text that matches extended
regular expressions
 fgrep
– Does not interpret regular expressions
– Returns results faster than the egrep
Course ILT Activity C-1

Using regular expressions in grep

and egrep
The vi editor
 One of the oldest and most popular
text editors available for Linux and
Course ILT

UNIX operating systems

– vim is an improved version for Linux
– Not easy, but portable

The vi editor, continued
 The vi editor is called bi-modal
because it functions in two modes:
Course ILT

– Command mode
 Performs editing tasks not related to
inserting text
– Insert mode
 Allows inserting text into the document
Entering insert mode using keyboard keys
Course ILT
Course ILT Key combinations

Course ILT Key combinations, continued

Course ILT Key combinations, continued
Course ILT Key combinations used at : prompt
Course ILT Activity C-2

Using the vi editor

Course ILT Activity C-3

Exploring vi options
Other common text editors
 pico (PIne COmposer) editor
 mcedit editor (Midnight Commander
Course ILT

 emacs (Editor MAcroS) editor
 xemacs editor
emacs editor
 Alternative to the vi editor that offers
equal functionality
Course ILT

 Not an easy-to-use editor as it must

memorize several key combinations
to work effectively

Course ILT emacs editor, continued
xemacs editor

 Version if emacs that runs in the

Course ILT

KDE or GNOME GUI environments

 Much easier to use than emacs
 May not be available in every Linux
distribution that contains a GUI
Course ILT xemacs editor, continued
Graphical text editors
 nedit editor
Course ILT
gedit editor

 gedit editor
Course ILT

– Text editor for the GNOME desktop

Kedit editors
 Kedit editor
– Text editor for the KDE desktop
Course ILT
Course ILT Activity C-4

Discussing common text editors

Unit summary
 Learned about the Linux directory
structure and Linux files, and used shell
Course ILT

wildcards to specify multiple file names

 Displayed the contents of text files and
binary files
 Searched text files for regular
expressions by using grep, and
identified common editors
 Used the vi editor