Linux+ Guide to Linux Certification Chapter Four Exploring Linux Filesystems

  • Published on
    12-Jan-2016

  • View
    217

  • Download
    5

Embed Size (px)

Transcript

  • 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 filenamesDisplay the contents of text files and binary filesSearch text files for regular expressions using grepIdentify common text editors used todayUse the vi editor to manipulate text files

  • The Linux Directory StructureDirectorySpecial file on the filesystem used to organize other files into a logical tree structureFigure 4-1: The Windows filesystem structure

  • The Linux Directory StructureAbsolute pathnameFull pathname to a certain file or directory starting from the root directoryFigure 4-2: The Linux filesystem structure

  • Changing DirectoriesHome directoryA directory on the file system set aside for users to store personal files and informationpwd command (print working directory)Linux command used to display the current directory in the directory treecd (change directory) commandLinux command used to change the current directory in the directory tree

  • Changing Directories~ metacharacterCan be used to refer to the current users home directoryCan be used to specify another users home directory by appending a username at the end of the ~ metacharacterRelative pathnamePathname of a target directory relative to your current directory in the tree

  • Changing DirectoriesSubdirectoryDirectory that resides within another directory in the directory treeTab-completionFeature of the BASH Shell that fills in the remaining characters of a unique filename or directory name when the user presses the Tab key

  • File TypesCommon file types:Text filesBinary data filesExecutable program filesDirectory filesLinked filesSpecial device filesNamed pipes and socket files

  • FilenamesFilenameUser-friendly identifier given to a fileExecutable programsFile that can be executed by the Linux OS to run in memory as a process and perform a useful functionFilename extensionsSeries of identifiers following a dot (.) at the end of a filename used to denote the type of the file

  • FilenamesTable 4-1: Common filename extensions

  • FilenamesTable 4-1 (continued): Common filename extensions

  • FilenamesTable 4-1 (continued): Common filename extensions

  • Listing Filesls commandLinux command used to list the files in a given directoryMost common method for displaying filesDisplays all the files in the current directory in columnar formatHowever, you may also pass an argument to the ls command indicating the directory to be listed if different from current directory listing

  • Listing Filesll commandAlias for the ls -l commandGives a long file listingFile commandLinux command that displays the file type of a specified filename

  • Listing FilesText fileFile that stores information in a readable text formatSome filenames inside each users home directory represent important configuration files or program directoriesHidden filesFiles that are not normally displayed to the user via common filesystem commands

  • Listing FilesTable 4-2: Common options to the ls command

  • Listing FilesTable 4-2 (continued): Common options to the ls command

  • Wildcard MetacharactersWildcard metacharacterCan simplify commands that specify more than one filename on the command lineInterpreted by the shell and can be used with most common Linux filesystem commandsMatches certain portions of filenames, or the entire filename itself

  • Wildcard MetacharactersTable 4-3: Wildcard metacharacters

  • Displaying Content of Text FilesConcatenationJoining of text together to make one larger wholeIn Linux, words and strings of text are joined together to form a displayed filecat commandLinux command used to display (or concatenate) the entire contents of a text file to the screen

  • Displaying Content of Text FilesLog filesFile that contains past system eventstac commandLinux 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

  • Displaying Content of Text Fileshead commandBy default, displays the first 10 lines (including blank lines) of a text file to the terminal screenCan also take a numeric option specifying a different number of lines to displaytail commandBy default, displays the last 10 lines (including blank lines) of a text file to the terminal screenCan also take a numeric option specifying a different number of lines to display

  • Displaying Content of Text Filesmore commandLinux command used to display a text file page-by-page and line-by-line on the terminal screenGets its name from the pg command once used on UNIX systemThe more command does more than pg did

  • Displaying Content of Text Filesless commandLinux command used to display to display a text file page-by-page on the terminal screenUsers may then use the cursor keys to navigate the fileThe 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

  • Displaying the Contents of Binary FilesIt is important to employ text file commands as cat, tac, head, tail, more, and less only on files that contain textOtherwise you may find yourself with random output on the terminal screen, or even a dysfunctional screenstrings commandsLinux command used to search for and display text characters in a binary file

  • Displaying the Contents of Binary Filesod commandLinux 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

  • Searching for Text within FilesText toolsFile that stores information in a readable text formatRegular expressions (regxp)Special metacharacters used to match patterns of text within text filesCommonly used by many text tool commands such as grep

  • Searching for Text within FilesText tools and programming languages that use regular expressions include:grepawksedviemacs

  • Searching for Text within FilesText tools and programming languages that use regular expressions include (continued):exedC++PERLTcl

  • Regular ExpressionsDifferences between regular expressions and wildcard metacharacters include:Wildcard metacharacters are interpreted by the shellRegular expressions are interpreted by a text tool programWildcard metacharacters match characters in filenames (or directory names) on a Linux filesystemRegular expressions match characters within text files on a Linux filesystem

  • Regular ExpressionsDifferences between regular expressions and wildcard metacharacters include (continued):Wildcard metacharacters typically have different definitions than regular expressionsThere are more regular expressions than wildcard metacharactersRegular expressions are divided into two different categories:Commonextended

  • Regular ExpressionsTable 4-4: Regular expressions

  • Regular ExpressionsTable 4-4 (continued): Regular expressions

  • The grep CommandgrepStands for Global Regular Expression PrintUsed to display lines in a text file that match a certain common regular expressionUse the egrep command to display lines of text that match extended regular expressionsThe fgrep command does interpret any regular expressions and consequently returns results much faster than the egrep command

  • The vi EditorOne of the oldest and most popular visual text editors available for UNIX operating systemsIts Linux equivalent (known as vimvi improved) is standard on almost every Linux distribution as a resultThough not the easiest of the editors to use when editing text files, it has the advantage of portability

  • The vi EditorThe vi editor is called a bi-modal editor as it functions in one of two modes:Command modeAllows a user to perform any available text editing task that is not related to inserting text into the documentInsert modeAllows the user to insert text into the document but does not allow any other functionality

  • The vi EditorTable 4-5: Common keyboard keys used to change to and from insert mode

  • The vi EditorTable 4-6: Key combinations commonly used in command mode

  • The vi EditorTable 4-6 (continued): Key combinations commonly used in command mode

  • The vi EditorTable 4-6 (continued): Key combinations commonly used in command mode

  • The vi EditorTable 4-7: Key combinations commonly used at the command mode : prompt

  • Other Common Text EditorsPico (PIne COmposer) editorBy far, the easiest alternative to the vi editorCommonly used to create and edit e-mailsMcedit editor (Midnight Commander Editor)Resembles pico yet had more functionality, support for regular expressions, and ability to use the mouse for highlighting text

  • Other Common Text EditorsEmacs (Editor MAcroS) editorAlternative to the vi editor that offers an equal set of functionalityLike pico, uses the Ctrl key in combination with certain letters to perform special functionsYet can be used with the LISP (LSIt Processing) artificial programming language and supports hundreds of key board functions like the vi editor

  • Other Common Text EditorsTable 4-8: Keyboard functions commonly used in the GNU emacs editor

  • Other Common Text EditorsThe emacs editor is not an easy-to-use editor as it must memorize several key combinations to work effectivelyXemacs editorVersion if emacs that runs in the KDE or GNOME GUI environmentsMuch easier to use than emacs

  • Other Common Text EditorsFigure 4-3: The xemacs test editor

  • Other Common Text EditorsThe xemacs editor may not be available in every Linux distribution that contains a GUI environmentTwo commonly used graphical text editors available in most Linux distributions:Xedit editorNedit editor

  • Other Common Text EditorsFigure 4-4: The exedit text editor

  • Other Common Text EditorsFigure 4-5: The nedit text editor

  • Other Common Text EditorsGedit editorText editor for the GNOME desktopKedit editorText editor for the KDE desktopThe gedit and kedit editors are similar to nedit yet offer more functionality

  • Other Common Text EditorsFigure 4-6: The gedit text editor

  • Other Common Text EditorsFigure 4-7: The kedit text editor

  • Chapter SummaryThe 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 pathnamesThere are many types of files that may exist on the Linux filesystemThe ls command can be used to view filenames and offers a wide range of options to modify this view

  • Chapter SummaryWildcard metacharacters can be used to simplify the selection of several files when using common Linux file commandsText files are the common file type whose contents may be viewed by several utilities such as head, tail, cat, tac, more, and lessRegular expressions can be used to specify certain patterns of text when used with certain programming languages and text tools such as grepVi (vim) is a powerful, bi-modal text editor that is standard on most UNIX and Linux systems

Recommended

View more >