Course ILT
Exploring Linux filesystems Unit objectives Discuss the directory structure and file 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 editors
Course ILT
Topic A Topic A: Linux files and directories Topic B: Displaying the contents of files Topic C: Searching and editing text files
Course ILT
The Linux directory structure
The Linux directory structure Course ILT
Directory – Special file used to organize other files into a logical structure
Absolute pathname – Full pathname to a certain file or directory starting from the root directory
Home directory Course ILT
Home directory – A directory for users to store personal files and information – Each user has a subdirectory
Changing directories Course ILT
pwd (print working directory) – Used to identify the current directory path
cd (change directory) – Used to move from one directory to another
The ~ metacharacter and relative paths
Course ILT
~ – Refers to the current user’s home directory – 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
Tab-completion – 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 structure
Course ILT
File types
Text files Binary data files Executable program files Directory files Linked files Special device files Named pipes and socket files
Filenames Course ILT
Filename – User-friendly identifier given to a file
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
Course ILT
The ls command Used to list the files in a directory Most common method for displaying files Displays all the files in the current directory – You can use an argument with ls to list a directory different from current one
Course ILT
Ls –F file type characters
@ Linked file * Executable file / Subdirectory = Socket file | Named pipe
The file command Course ILT
File command – Displays detailed information about any file – Works with multiple files – Uses * to include all files in a directory
Hidden files Course ILT
Hidden files – Files that are not normally displayed with common filesystem commands – Represent important configuration files or program directories
Course ILT
ls command options
continued
Course ILT
ls command options, continued
Course ILT
Activity A-2
Examining files and file types
Course ILT
Wildcard metacharacters Can simplify more than one filename to a command Interpreted by the shell and can be used with most filesystem commands Matches certain portions of filenames or an entire filename
continued
Course ILT
Wildcard metacharacters, continued
Course ILT
Activity A-3
Using wildcard metacharacters
Course ILT
Topic B Topic A: Linux files and directories Topic B: Displaying the contents of files Topic C: Searching and editing text files
Displaying content of text files Course ILT
cat command – Display the entire contents of a text file to 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 continued
Displaying content of text files, continued
Course ILT
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
Other text file viewing commands Course ILT
more command – Displays 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 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
Course ILT
strings commands – Linux command used to search for and 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
Course ILT
Topic C Topic A: Linux files and directories Topic B: Displaying the contents of files Topic C: Searching and editing text files
Searching for text within files Course ILT
Regular expressions (regexp) – Special metacharacters used to match patterns of text within text files – Commonly used by many text tool commands such as grep
Course ILT
Using regular expressions
grep awk sed vi emacs ex ed PERL
Course ILT
Regular expressions and wildcards Wildcard metacharacters are 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
continued
Course ILT
Regular expressions and wildcards, continued
Wildcard metacharacters regular expressions usually have different definitions than wildcard metacharacters More metacharacters are available for regular expressions Regular expressions are divided into two different categories: – Common – Extended
Course ILT
Regular expressions
The grep command Course ILT
grep – Displays lines in a text file that match a common regular expression
egrep – Displays text that matches extended regular expressions
fgrep – Does not interpret regular expressions – Returns results faster than the egrep command
Course ILT
Activity C-1
Using regular expressions in grep and egrep
Course ILT
The vi editor One of the oldest and most popular text editors available for Linux and UNIX operating systems – vim is an improved version for Linux – Not easy, but portable
continued
Course ILT
The vi editor, continued The vi editor is called bi-modal because it functions in two modes: – Command mode Performs editing tasks not related to inserting text
– Insert mode Allows inserting text into the document
Course ILT
Entering insert mode using keyboard keys
Course ILT
Key combinations
continued
Course ILT
Key combinations, continued
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
Course ILT
Other common text editors pico (PIne COmposer) editor mcedit editor (Midnight Commander Editor) emacs (Editor MAcroS) editor xemacs editor
Course ILT
emacs editor Alternative to the vi editor that offers equal functionality Not an easy-to-use editor as it must memorize several key combinations to work effectively
continued
Course ILT
emacs editor, continued
Course ILT
xemacs editor Version if emacs that runs in the KDE or GNOME GUI environments Much easier to use than emacs May not be available in every Linux distribution that contains a GUI environment
Course ILT
xemacs editor, continued
Graphical text editors Course ILT
nedit editor
gedit editor Course ILT
gedit editor – Text editor for the GNOME desktop
Kedit editors Course ILT
Kedit editor – Text editor for the KDE desktop
Course ILT
Activity C-4
Discussing common text editors
Course ILT
Unit summary Learned about the Linux directory structure and Linux files, and used shell 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