430 likes | 447 Views
Linux+ Guide to Linux Certification, Second Edition. Chapter 4 Exploring Linux Filesystems. Objectives. Understand and navigate the Linux directory structure using relative and absolute pathnames Describe the various types of Linux files View filenames and file types
E N D
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems
Objectives • 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 Linux+ Guide to Linux Certification, 2e
Objectives (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 Linux+ Guide to Linux Certification, 2e
The 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 Linux+ Guide to Linux Certification, 2e
The Linux Directory Structure (continued) Figure 4-1: The Windows filesystem structure Figure 4-2: The Linux filesystem structure Linux+ Guide to Linux Certification, 2e
Changing 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 Linux+ Guide to Linux Certification, 2e
Changing 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 Linux+ Guide to Linux Certification, 2e
Viewing 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 Linux+ Guide to Linux Certification, 2e
Viewing 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 Linux+ Guide to Linux Certification, 2e
Filenames • 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 Linux+ Guide to Linux Certification, 2e
Filenames (continued) Table 4-1: Common filename extensions Linux+ Guide to Linux Certification, 2e
Filenames (continued) Table 4-1 (continued): Common filename extensions Linux+ Guide to Linux Certification, 2e
Listing 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 Linux+ Guide to Linux Certification, 2e
Listing 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 Linux+ Guide to Linux Certification, 2e
Listing Files (continued) Table 4-2: Common options to the ls command Linux+ Guide to Linux Certification, 2e
Listing Files (continued) Table 4-2 (continued): Common options to the ls command Linux+ Guide to Linux Certification, 2e
Wildcard Metacharacters • Wildcard metacharacter: Used to simplify commands specifying multiple filenames • Can be used with most Linux filesystem commands Linux+ Guide to Linux Certification, 2e
Wildcard Metacharacters (continued) Table 4-3: Wildcard metacharacters Linux+ Guide to Linux Certification, 2e
Displaying 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 Linux+ Guide to Linux Certification, 2e
Displaying 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 Linux+ Guide to Linux Certification, 2e
Displaying 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 Linux+ Guide to Linux Certification, 2e
Displaying 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) Linux+ Guide to Linux Certification, 2e
Searching 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 Linux+ Guide to Linux Certification, 2e
Regular 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 Linux+ Guide to Linux Certification, 2e
Regular Expressions (continued) Table 4-4: Regular expressions Linux+ Guide to Linux Certification, 2e
Regular Expressions (continued) Table 4-4 (continued): Regular expressions Linux+ Guide to Linux Certification, 2e
The 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 Linux+ Guide to Linux Certification, 2e
Editing 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 Linux+ Guide to Linux Certification, 2e
Editing Text Files: The vi Editor (continued) Table 4-5: Common keyboard keys used to change to and from insert mode Linux+ Guide to Linux Certification, 2e
Editing Text Files: The vi Editor (continued) Table 4-6: Key combinations commonly used in command mode Linux+ Guide to Linux Certification, 2e
Editing Text Files: The vi Editor (continued) Table 4-6 (continued): Key combinations commonly used in command mode Linux+ Guide to Linux Certification, 2e
Editing Text Files: The vi Editor (continued) Table 4-6 (continued): Key combinations commonly used in command mode Linux+ Guide to Linux Certification, 2e
Editing Text Files: The vi Editor (continued) Table 4-7: Key combinations commonly used at the command mode : prompt Linux+ Guide to Linux Certification, 2e
Other 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 Linux+ Guide to Linux Certification, 2e
Other Common Text Editors (continued) Table 4-8: Keyboard functions commonly used in the GNU emacs editor Linux+ Guide to Linux Certification, 2e
Other 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 Linux+ Guide to Linux Certification, 2e
Other Common Text Editors (continued) Figure 4-3: The xemacs text editor Linux+ Guide to Linux Certification, 2e
Other 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 Linux+ Guide to Linux Certification, 2e
Other Common Text Editors (continued) Figure 4-4: The nedit text editor Linux+ Guide to Linux Certification, 2e
Other Common Text Editors (continued) Figure 4-5: The gedit text editor Linux+ Guide to Linux Certification, 2e
Other Common Text Editors (continued) Figure 4-6: The kedit text editor Linux+ Guide to Linux Certification, 2e
Summary • 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 Linux+ Guide to Linux Certification, 2e
Summary (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 Linux+ Guide to Linux Certification, 2e