Linux+ Guide to Linux Certification, Third Edition Chapter 3 Exploring Linux Filesystems.

  • Published on
    12-Jan-2016

  • View
    218

  • Download
    3

Embed Size (px)

Transcript

  • Linux+ Guide to Linux Certification, Third EditionChapter 3Exploring Linux Filesystems

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*ObjectivesUnderstand and navigate the Linux directory structure using relative and absolute pathnamesDescribe the various types of Linux filesView filenames and file typesUse shell wildcards to specify multiple filenames

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Objectives (continued)Display the contents of text files and binary filesSearch text files for regular expressions using grepUse the vi editor to manipulate text filesIdentify common alternatives to the vi text editor used today

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*The Linux Directory StructureDirectory: Used to organize other files into a logical tree structureStored in a filesystem of a specific partition in the hard diskAbsolute pathname: Pathname from the root directory to a certain file or directoryRoot: The top level directoryReferred to using the / characterForms root of a hierarchical tree

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*The Linux Directory Structure (continued)Figure 3-1: The Windows filesystem structureFigure 3-2: The Linux filesystem structure

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Changing DirectoriesHome directory: unique to each user~ metacharacter used to refer to home directorypwd (print working directory) command: displays current directory in the directory treecd (change directory) command: change the current directory in the directory tree Argument specifies the destination directoryRelative pathname: pathname of file or directory relative to current directory

    Linux+ Guide to Linux Certification, 3e

  • Changing Directories (continued)Parent directory: directory one step closer to the root of the treeReferred to by .. (two dots)Subdirectory: directory residing within another directoryTab-completion: pressing the Tab key fills in remaining characters of a unique filename or directory nameBASH shell featureAlerts user if there is more than one possible matchLinux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Viewing Files and Directories: File TypesText files: store information in a readable text format, contain configuration informationBinary data files: store information associated with executable programsExecutable program filesDirectory files: serve as placeholders to organize other filesLinux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Viewing Files and Directories: File Types (continued)Linked files: associated with another fileSpecial device files: represent system devicesNamed pipes: identify channel that passes information between processesSocket files: allow a process on another computer to write to a local file

    Linux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*FilenamesFilename: identifier given to a fileUp to 255 charactersCan use alphanumeric characters, dash (-), underscore (_), and dot (.) Filename extensions: identifiers following a dot (.) at end of filename Denote file typeMost files on Linux do not have filename extensions

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Table 3-1: Common filename extensions

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Listing Filesls command: List the files in a directoryMay pass an argument indicating the directory to be listedF option: Argument to indicate file typesl option: Argument to list long file listings

    Linux+ Guide to Linux Certification, 3e

  • Listing Files (continued)Long listing for each file includes eight componentsFile type characterList of permissions (mode of the file)Hard link countOwnerGroup ownerFile sizeMost recent modification timeFilenameLinux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Listing Files (continued)Alias: shortcut for a commandll command: Alias for ls -lFile command: displays file type of any fileArgument indicates what file or files to analyzeIdentifies between different types of executable filesIdentifies empty filesHidden files: files not normally displayed to userConfiguration files often hiddenFilenames start with a dot (.)ls a command: displays hidden files

    Linux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Listing Files (continued)Table 3-2: Common options to the ls command

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Listing Files (continued)Table 3-2 (continued): Common options to the ls command

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Wildcard MetacharactersWildcard metacharacter: used to simplify commands specifying multiple filenamesCan match the entire filename or portions of filenamesCan be used with most Linux filesystem commands

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Wildcard Metacharacters (continued)Table 3-3: Wildcard metacharacters

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Displaying Content of Text FilesConcatenation: joining text togethercat command: displays (concatenates) contents of a text file to the screen-n option: displays line number and contentsLog files: contain records of past system eventsNew events appended to endtac command: displays contents of a text file in reverse order

    Linux+ Guide to Linux Certification, 3e

  • Displaying Content of Text Files (Continued)head command: view first ten lines of a filetail command: view last ten lines of a fileFor head and tail commandsLine count includes blank linesCan provide numeric option to specify the number of lines to be displayed (e.g., head -2 filename)Linux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Displaying Content of Text Files (continued)Large text files can not be viewed using the cat command, because the screen will only fit a portion of the filemore command: displays text files page-by-pagePressing Spacebar displays the next pagePressing Enter displays the next lineless command: same as more command, but can also use cursor to scroll

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Displaying Content of Text Files (continued)Users can use keyboard shortcuts to interact with shell while in more and less commands. e.g., pressing h key gets Help screene.g., pressing q key quits more and less commandsmore and less can be used with output of other commands If output is too large to fit on terminal screen, use | metacharacter and more or less commande.g., ls -l | more

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Displaying the Contents of Binary FilesTypically use program that created the filestrings command: searches for and displays text characters in a binary fileMight indicate purpose of binary fileod command: displays contents of file in octal format (numeric base 8 format)-x option displays contents of the file in hexadecimal format (numeric base 16 format)

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Searching for Text Within FilesText tools: commands that search for and manipulate textRegular expressions (regexp): text wildcards that ease the search for specific textMatch patterns of text within a text documentUsed by many text tools and programming languagesIncluding grep, emacs, C++, PERL, and many more

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Regular ExpressionsDifferent from wildcard metacharactersWildcard metacharacters interpreted by shell; regexps interpreted by text toolsWildcard metacharacters match characters in filenames; regexps match characters within text filesWildcard metacharacters have different definitions that regexpsMore regexps than wildcard metacharactersRegular expressions are divided into common regexps and extended regexps

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Table 3-4: Regular expressions

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*The grep Commandgrep (global regular expression print) command: displays lines in a text file that match common regexpsegrep command: displays lines in a text file that match extended regexpsCan be written as grep -Efgrep command: does not interpret any regular expressions Returns results much faster than egrepCan be written as grep -F

    Linux+ Guide to Linux Certification, 3e

  • The grep Command (continued)grep requires two argumentsText to search for Can use regular expressions Files in which to searchgrep is case sensitiveFor case-insensitive search, use i optiongrep matches patterns of text, ignoring division into wordsTo search only for occurrences of a word, surround it by space characters

    Linux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Editing Text Files: The vi EditorOne of the oldest and most popular text editors for UNIX OSsVim: Linux equivalent of viStandard on most Linux distributionsAdvantage is portability, not usabilityUsed on Unix and LinuxBi-modal editor (two possible modes):Command mode: Performs text editing tasks not related to inserting textInsert mode: Inserts text, but nothing elseUser environment is customizableLinux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Editing Text Files: The vi Editor (continued)Table 3-5: Common keyboard keys used to change to and from insert mode

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Editing Text Files: The vi Editor (continued)Table 3-6: Key combinations commonly used in command mode

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Editing Text Files: The vi Editor (continued)Table 3-6 (continued): Key combinations commonly used in command mode

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Editing Text Files: The vi Editor (continued)Table 3-6 (continued): Key combinations commonly used in command mode

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Editing Text Files: The vi Editor (continued)Table 3-7: Key combinations commonly used at the command mode : prompt

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Other Common Text EditorsEmacs (Editor MACroS) editor: comparable functionality to viCtrl key combinations to perform special functions Supports LISP (LISt Processing) artificial intelligence programming languageEmacs editor is not easy to use Must memorize key combinationEmacs can be run in a GUI environment to get a graphical version of the editorMuch easier to use; icons replace key combinations

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Other Common Text Editors (continued)Table 3-8: Keyboard functions commonly used in the GNU Emacs editor

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Other Common Text Editors (continued) Figure 3-3: A graphical Emacs session

    Linux+ Guide to Linux Certification, 3e

  • Other Common Text Editors (continued)Nano editor: text editor that uses Ctrl key combinations for performing functionsBased on the pine UNIX editorCtrl key combinations listed at the bottom of the screenVery basic and easy-to-useUsed by Linux administrators to modify files when advanced functionality is not neededLinux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Other Common Text Editors (continued)gedit editor: a graphical text editor functional in a GUI environmentDoes not have advanced functionality like vi and EmacsEasiest editor to useFunctionality is analogous to the Windows Wordpad and Notepad editors

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Other Common Text Editors (continued)Figure 3-4: The gedit text editor

    Linux+ Guide to Linux Certification, 3e

  • SummaryThe Linux filesystem is arranged hierarchically using a series of directories to store filesLocation of directories and files can be described using absolute or relative pathnamesLinux filesystem can contain many types of filestext files, binary data, executable programs, directories, linked files, and special device filesThe ls command is used to view filenamesWide range of options to modify viewsLinux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Summary (continued)Wildcard metacharacters are special keyboard characterscan simplify selection of several files when using common Linux file commandsText files are the most common file type whose contents can be viewed by several utilities, such as head, tail, cat, tac, more, and less

    Linux+ Guide to Linux Certification, 3e*

    Linux+ Guide to Linux Certification, 3e

  • Linux+ Guide to Linux Certification, 3e*Summary (continued)

    Regular expression metacharacters can be used to specify certain patterns of text used with certain programming languages and text tool utilities such as grepvi (vim) is a powerful, bimodal text editor that is standard on most UNIX and Linux systems

    Linux+ Guide to Linux Certification, 3e

Recommended

View more >