Transcript
Page 1: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Linux+ Guide to Linux Certification

Chapter Four

Exploring Linux Filesystems

Page 2: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

ObjectivesObjectives

• 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• Identify common text editors used today• Use the vi editor to manipulate text files

Page 3: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

The Linux Directory StructureThe Linux Directory Structure

• Directory– Special file on the filesystem used to organize other files

into a logical tree structure

Figure 4-1: The Windows filesystem structure

Page 4: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

The Linux Directory StructureThe Linux Directory Structure

• Absolute pathname– Full pathname to a certain file or directory starting from the root

directory

Figure 4-2: The Linux filesystem structure

Page 5: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Changing DirectoriesChanging Directories

• Home directory– A directory on the file system set aside for users

to store personal files and information

• pwd command (print working directory)– Linux command used to display the current

directory in the directory tree

• cd (change directory) command– Linux command used to change the current

directory in the directory tree

Page 6: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Changing DirectoriesChanging Directories

• ~ metacharacter– Can be used to refer to the current user’s home

directory– Can be used to specify another user’s home

directory by appending a username at the end of the ~ metacharacter

• Relative pathname– Pathname of a target directory relative to your

current directory in the tree

Page 7: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Changing DirectoriesChanging Directories

• Subdirectory– Directory that resides within another directory in

the directory tree

• Tab-completion– Feature of the BASH Shell that fills in the

remaining characters of a unique filename or directory name when the user presses the Tab key

Page 8: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

File TypesFile Types

• Common file types:– Text files– Binary data files– Executable program files– Directory files– Linked files– Special device files– Named pipes and socket files

Page 9: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

FilenamesFilenames

• Filename– User-friendly identifier given to a file

• Executable programs– File that can be executed by the Linux OS to run

in memory as a process and perform a useful function

• Filename extensions– Series of identifiers following a dot (.) at the end

of a filename used to denote the type of the file

Page 10: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

FilenamesFilenames

Table 4-1: Common filename extensions

Page 11: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

FilenamesFilenames

Table 4-1 (continued): Common filename extensions

Page 12: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

FilenamesFilenames

Table 4-1 (continued): Common filename extensions

Page 13: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Listing FilesListing Files

• ls command– Linux command used to list the files in a given

directory– Most common method for displaying files– Displays all the files in the current directory in

columnar format• However, you may also pass an argument to the ls

command indicating the directory to be listed if different from current directory listing

Page 14: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Listing FilesListing Files

• ll command– Alias for the ls -l command– Gives a long file listing

• File command– Linux command that displays the file type of a

specified filename

Page 15: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Listing FilesListing Files

• Text file– File that stores information in a readable text

format

• Some filenames inside each user’s home directory represent important configuration files or program directories

• Hidden files– Files that are not normally displayed to the user

via common filesystem commands

Page 16: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Listing FilesListing Files

Table 4-2: Common options to the ls command

Page 17: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Listing FilesListing Files

Table 4-2 (continued): Common options to the ls command

Page 18: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Wildcard MetacharactersWildcard Metacharacters

• Wildcard metacharacter– Can simplify commands that specify more than

one filename on the command line– Interpreted by the shell and can be used with most

common Linux filesystem commands– Matches certain portions of filenames, or the

entire filename itself

Page 19: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Wildcard MetacharactersWildcard Metacharacters

Table 4-3: Wildcard metacharacters

Page 20: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Displaying Content of Text FilesDisplaying Content of Text Files

• Concatenation– Joining of text together to make one larger whole– In Linux, words and strings of text are joined

together to form a displayed file

• cat command– Linux command used to display (or concatenate)

the entire contents of a text file to the screen

Page 21: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Displaying Content of Text FilesDisplaying Content of Text Files

• Log files– File that contains past system events

• tac command– Linux command that displays a file to the screen

beginning with the last line of the file and ending with the first line of the file

Page 22: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Displaying Content of Text FilesDisplaying Content of Text Files

• head command– By default, 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

• tail command– By default, displays the last 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

Page 23: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Displaying Content of Text FilesDisplaying Content of Text Files

• more command– Linux command used to display a text file page-

by-page and line-by-line on the terminal screen– Gets its name from the pg command once used on

UNIX system– The more command does more than pg did

Page 24: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Displaying Content of Text FilesDisplaying Content of Text Files

• less command– Linux command used to display to display a text

file page-by-page on the terminal screen– Users may then use the cursor keys to navigate

the file

• The more and less commands can also be used in conjunction with the output of other commands if that output is too large to fit on the terminal screen

Page 25: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Displaying the Contents of Binary Displaying the Contents of Binary FilesFiles

• It is important to employ text file commands as cat, tac, head, tail, more, and less only on files that contain text– Otherwise you may find yourself with random output

on the terminal screen, or even a dysfunctional screen

• strings commands– Linux command used to search for and display text

characters in a binary file

Page 26: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Displaying the Contents of Binary Displaying the Contents of Binary FilesFiles

• 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

Page 27: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Searching for Text within FilesSearching for Text within Files

• Text tools– File that stores information in a readable text

format

• Regular expressions (regxp)– Special metacharacters used to match patterns of

text within text files– Commonly used by many text tool commands

such as grep

Page 28: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Searching for Text within FilesSearching for Text within Files

• Text tools and programming languages that use regular expressions include:– grep– awk– sed– vi– emacs

Page 29: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Searching for Text within FilesSearching for Text within Files

• Text tools and programming languages that use regular expressions include (continued):– ex– ed– C++– PERL– Tcl

Page 30: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Regular ExpressionsRegular Expressions

• Differences between regular expressions and wildcard metacharacters include:– Wildcard metacharacters are interpreted by the shell

• Regular expressions are interpreted by a text tool program

– Wildcard metacharacters match characters in filenames (or directory names) on a Linux filesystem

• Regular expressions match characters within text files on a Linux filesystem

Page 31: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Regular ExpressionsRegular Expressions

• Differences between regular expressions and wildcard metacharacters include (continued):– Wildcard metacharacters typically have different

definitions than regular expressions– There are more regular expressions than wildcard

metacharacters– Regular expressions are divided into two different

categories:• Common• extended

Page 32: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Regular ExpressionsRegular Expressions

Table 4-4: Regular expressions

Page 33: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Regular ExpressionsRegular Expressions

Table 4-4 (continued): Regular expressions

Page 34: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

The grep CommandThe grep Command

• grep– Stands for Global Regular Expression Print– Used to display lines in a text file that match a certain

common regular expression

• Use the egrep command to display lines of text that match extended regular expressions

• The fgrep command does interpret any regular expressions and consequently returns results much faster than the egrep command

Page 35: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

The vi EditorThe vi Editor

• One of the oldest and most popular visual text editors available for UNIX operating systems– Its Linux equivalent (known as vim—vi

improved) is standard on almost every Linux distribution as a result

• Though not the easiest of the editors to use when editing text files, it has the advantage of portability

Page 36: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

The vi EditorThe vi Editor

• The vi editor is called a bi-modal editor as it functions in one of two modes:– Command mode

• Allows a user to perform any available text editing task that is not related to inserting text into the document

– Insert mode• Allows the user to insert text into the document but

does not allow any other functionality

Page 37: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

The vi EditorThe vi Editor

Table 4-5: Common keyboard keys used to change to and from insert mode

Page 38: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

The vi EditorThe vi Editor

Table 4-6: Key combinations commonly used in command mode

Page 39: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

The vi EditorThe vi Editor

Table 4-6 (continued):Key combinations commonly used in command mode

Page 40: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

The vi EditorThe vi Editor

Table 4-6 (continued):Key combinations commonly used in command mode

Page 41: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

The vi EditorThe vi Editor

Table 4-7:Key combinations commonly used at the command mode : prompt

Page 42: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Other Common Text EditorsOther Common Text Editors

• Pico (PIne COmposer) editor– By far, the easiest alternative to the vi editor– Commonly used to create and edit e-mails

• Mcedit editor (Midnight Commander Editor)– Resembles pico yet had more functionality,

support for regular expressions, and ability to use the mouse for highlighting text

Page 43: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Other Common Text EditorsOther Common Text Editors

• Emacs (Editor MAcroS) editor– Alternative to the vi editor that offers an equal set

of functionality– Like pico, uses the Ctrl key in combination with

certain letters to perform special functions• Yet can be used with the LISP (LSIt Processing)

artificial programming language and supports hundreds of key board functions like the vi editor

Page 44: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Other Common Text EditorsOther Common Text Editors

Table 4-8: Keyboard functions commonly used in the GNU emacs editor

Page 45: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Other Common Text EditorsOther Common Text Editors

• The emacs editor is not an easy-to-use editor as it must memorize several key combinations to work effectively

• Xemacs editor– Version if emacs that runs in the KDE or

GNOME GUI environments– Much easier to use than emacs

Page 46: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Other Common Text EditorsOther Common Text Editors

Figure 4-3: The xemacs test editor

Page 47: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Other Common Text EditorsOther Common Text Editors

• The xemacs editor may not be available in every Linux distribution that contains a GUI environment

• Two commonly used graphical text editors available in most Linux distributions:– Xedit editor– Nedit editor

Page 48: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Other Common Text EditorsOther Common Text Editors

Figure 4-4: The exedit text editor

Page 49: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Other Common Text EditorsOther Common Text Editors

Figure 4-5: The nedit text editor

Page 50: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Other Common Text EditorsOther Common Text Editors

• Gedit editor– Text editor for the GNOME desktop

• Kedit editor– Text editor for the KDE desktop

• The gedit and kedit editors are similar to nedit yet offer more functionality

Page 51: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Other Common Text EditorsOther Common Text Editors

Figure 4-6: The gedit text editor

Page 52: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Other Common Text EditorsOther Common Text Editors

Figure 4-7: The kedit text editor

Page 53: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Chapter SummaryChapter Summary

• The Linux filesystem is arranged hierarchically using a series of directories to store files, and the location of these directories and files can be described using absolute or relative pathnames

• There are many types of files that may exist on the Linux filesystem

• The ls command can be used to view filenames and offers a wide range of options to modify this view

Page 54: Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

Chapter SummaryChapter Summary

• Wildcard metacharacters can be used to simplify the selection of several files when using common Linux file commands

• Text files are the common file type whose contents may be viewed by several utilities such as head, tail, cat, tac, more, and less

• Regular expressions can be used to specify certain patterns of text when used with certain programming languages and text tools such as grep

• Vi (vim) is a powerful, bi-modal text editor that is standard on most UNIX and Linux systems


Recommended