2-filehierarchy

44
Exploring Linux Filesystems

Upload: robert-mathew-karf

Post on 12-Nov-2015

4 views

Category:

Documents


0 download

DESCRIPTION

file hirarki

TRANSCRIPT

  • Exploring Linux FilesystemsExploring Linux Filesystems

  • Objectives Understand and navigate the Linux

    directory structure using relative andabsolute pathnames

    Describe the various types of Linux files View filenames and file types Use shell wildcards to specify multiple

    filenames

    Understand and navigate the Linuxdirectory structure using relative andabsolute 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, 3e 2

  • Objectives (continued) Display the contents of text files and

    binary files Search text files for regular expressions

    using grep Use the vi editor to manipulate text files Identify common alternatives to the vi

    text editor used today

    Display the contents of text files andbinary files

    Search text files for regular expressionsusing grep

    Use the vi editor to manipulate text files Identify common alternatives to the vi

    text editor used today

    Linux+ Guide to Linux Certification, 3e 3

  • The Linux Directory Structure Directory: Used to organize other files

    into a logical tree structure Stored in a filesystem of a specific partition

    in the hard disk Absolute pathname: Pathname from the

    root directory to a certain file or directory Root: The top level directory Referred to using the / character Forms root of a hierarchical tree

    Directory: Used to organize other filesinto a logical tree structure Stored in a filesystem of a specific partition

    in the hard disk Absolute pathname: Pathname from the

    root directory to a certain file or directory Root: The top level directory Referred to using the / character Forms root of a hierarchical tree

    Linux+ Guide to Linux Certification, 3e 4

  • The Linux Directory Structure(continued)

    Linux+ Guide to Linux Certification, 3e 5

    Figure 3-1: The Windows file system structure

  • The Linux Directory Structure(continued)

    Linux+ Guide to Linux Certification, 3e 6Figure 3-2: The Linux file system structure

  • Changing Directories Home directory: unique to each user

    ~ metacharacter used to refer to home directory pwd (print working directory) command:

    displays current directory in the directorytree

    cd (change directory) command: changethe current directory in the directory tree Argument specifies the destination directory

    Relative pathname: pathname of file ordirectory relative to current directory

    Home directory: unique to each user ~ metacharacter used to refer to home directory

    pwd (print working directory) command:displays current directory in the directorytree

    cd (change directory) command: changethe current directory in the directory tree Argument specifies the destination directory

    Relative pathname: pathname of file ordirectory relative to current directory

    Linux+ Guide to Linux Certification, 3e 7

  • Changing Directories (continued) Parent directory: directory one step closer

    to the root of the tree Referred to by .. (two dots)

    Subdirectory: directory residing withinanother directory

    Tab-completion: pressing the Tab key fillsin remaining characters of a uniquefilename or directory name BASH shell feature Alerts user if there is more than one possible

    match

    Parent directory: directory one step closerto the root of the tree Referred to by .. (two dots)

    Subdirectory: directory residing withinanother directory

    Tab-completion: pressing the Tab key fillsin remaining characters of a uniquefilename or directory name BASH shell feature Alerts user if there is more than one possible

    match

    Linux+ Guide to Linux Certification, 3e 8

  • Viewing Files and Directories: FileTypes Text files: store information in a readable

    text format, contain configurationinformation

    Binary data files: store informationassociated with executable programs

    Executable program files Directory files: serve as placeholders to

    organize other files

    Text files: store information in a readabletext format, contain configurationinformation

    Binary data files: store informationassociated with executable programs

    Executable program files Directory files: serve as placeholders to

    organize other files

    Linux+ Guide to Linux Certification, 3e 9

  • Viewing Files and Directories: FileTypes (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

    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, 3e 10

  • Filenames Filename: identifier given to a file Up to 255 characters Can use alphanumeric characters, dash (-),

    underscore (_), and dot (.) Filename extensions: identifiers

    following a dot (.) at end of filename Denote file type Most files on Linux do not have filename

    extensions

    Filename: identifier given to a file Up to 255 characters Can use alphanumeric characters, dash (-),

    underscore (_), and dot (.) Filename extensions: identifiers

    following a dot (.) at end of filename Denote file type Most files on Linux do not have filename

    extensions

    Linux+ Guide to Linux Certification, 3e 11

  • Linux+ Guide to Linux Certification, 3e 12

    Table 3-1: Common filename extensions

  • Listing Files ls command: List the files in a directory May pass an argument indicating the

    directory to be listed F option: Argument to indicate file types l option: Argument to list long file listings

    ls command: List the files in a directory May pass an argument indicating the

    directory to be listed F option: Argument to indicate file types l option: Argument to list long file listings

    Linux+ Guide to Linux Certification, 3e 13

  • Listing Files (continued) Long listing for each file includes eight

    components File type character List of permissions (mode of the file) Hard link count Owner Group owner File size Most recent modification time Filename

    Long listing for each file includes eightcomponents File type character List of permissions (mode of the file) Hard link count Owner Group owner File size Most recent modification time Filename

    Linux+ Guide to Linux Certification, 3e 14

  • Listing Files (continued) Alias: shortcut for a command

    ll command: Alias for ls -l File command: displays file type of any file

    Argument indicates what file or files to analyze Identifies between different types of executable

    files Identifies empty files

    Hidden files: files not normally displayed touser Configuration files often hidden Filenames start with a dot (.) ls a command: displays hidden files

    Alias: shortcut for a command ll command: Alias for ls -l

    File command: displays file type of any file Argument indicates what file or files to analyze Identifies between different types of executable

    files Identifies empty files

    Hidden files: files not normally displayed touser Configuration files often hidden Filenames start with a dot (.) ls a command: displays hidden files

    Linux+ Guide to Linux Certification, 3e 15

  • Listing Files (continued)

    Linux+ Guide to Linux Certification, 3e 16

    Table 3-2: Common options to the ls command

  • Listing Files (continued)

    Linux+ Guide to Linux Certification, 3e 17

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

  • Wildcard Metacharacters Wildcard metacharacter: used to simplify

    commands specifying multiple filenames Can match the entire filename or portions of

    filenames Can be used with most Linux filesystem

    commands

    Wildcard metacharacter: used to simplifycommands specifying multiple filenames Can match the entire filename or portions of

    filenames Can be used with most Linux filesystem

    commands

    Linux+ Guide to Linux Certification, 3e 18

  • Wildcard Metacharacters(continued)

    Linux+ Guide to Linux Certification, 3e 19

    Table 3-3: Wildcard metacharacters

  • Displaying Content of Text Files Concatenation: joining text together cat command: displays (concatenates)

    contents of a text file to the screen -n option: displays line number and contents

    Log files: contain records of past systemevents New events appended to end

    tac command: displays contents of atext file in reverse order

    Concatenation: joining text together cat command: displays (concatenates)

    contents of a text file to the screen -n option: displays line number and contents

    Log files: contain records of past systemevents New events appended to end

    tac command: displays contents of atext file in reverse order

    Linux+ Guide to Linux Certification, 3e 20

  • Displaying Content of Text Files(Continued) head command: view first ten lines of a

    file tail command: view last ten lines of a file For head and tail commands Line count includes blank lines Can provide numeric option to specify the

    number of lines to be displayed (e.g., head -2 filename)

    head command: view first ten lines of afile

    tail command: view last ten lines of a file For head and tail commands Line count includes blank lines Can provide numeric option to specify the

    number of lines to be displayed (e.g., head -2 filename)

    Linux+ Guide to Linux Certification, 3e 21

  • Displaying Content of Text Files(continued) Large text files can not be viewed using

    the cat command, because the screenwill only fit a portion of the file

    more command: displays text files page-by-page Pressing Spacebar displays the next page Pressing Enter displays the next line

    less command: same as morecommand, but can also use cursor toscroll

    Large text files can not be viewed usingthe cat command, because the screenwill only fit a portion of the file

    more command: displays text files page-by-page Pressing Spacebar displays the next page Pressing Enter displays the next line

    less command: same as morecommand, but can also use cursor toscroll

    Linux+ Guide to Linux Certification, 3e 22

  • Displaying Content of Text Files(continued) Users can use keyboard shortcuts to

    interact with shell while in more and lesscommands. e.g., pressing h key gets Help screen e.g., pressing q key quits more and less

    commands more 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 lesscommand

    e.g., ls -l | more

    Users can use keyboard shortcuts tointeract with shell while in more and lesscommands. e.g., pressing h key gets Help screen e.g., pressing q key quits more and less

    commands more 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 lesscommand

    e.g., ls -l | more

    Linux+ Guide to Linux Certification, 3e 23

  • Displaying the Contents of BinaryFiles 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 inoctal format (numeric base 8 format) -x option displays contents of the file in

    hexadecimal format (numeric base 16format)

    Typically use program that created thefile

    strings command: searches for anddisplays text characters in a binary file Might indicate purpose of binary file

    od command: displays contents of file inoctal format (numeric base 8 format) -x option displays contents of the file in

    hexadecimal format (numeric base 16format)

    Linux+ Guide to Linux Certification, 3e 24

  • Searching for Text Within Files Text tools: commands that search for and

    manipulate text Regular expressions (regexp): text

    wildcards that ease the search for specifictext Match patterns of text within a text document Used by many text tools and programming

    languages Including grep, emacs, C++, PERL, and many

    more

    Text tools: commands that search for andmanipulate text

    Regular expressions (regexp): textwildcards that ease the search for specifictext Match patterns of text within a text document Used by many text tools and programming

    languages Including grep, emacs, C++, PERL, and many

    more

    Linux+ Guide to Linux Certification, 3e 25

  • Regular Expressions Different from wildcard metacharacters

    Wildcard metacharacters interpreted by shell;regexps interpreted by text tools

    Wildcard metacharacters match characters infilenames; regexps match characters within textfiles

    Wildcard metacharacters have differentdefinitions that regexps

    More regexps than wildcard metacharacters Regular expressions are divided into

    common regexps and extended regexps

    Different from wildcard metacharacters Wildcard metacharacters interpreted by shell;

    regexps interpreted by text tools Wildcard metacharacters match characters in

    filenames; regexps match characters within textfiles

    Wildcard metacharacters have differentdefinitions that regexps

    More regexps than wildcard metacharacters Regular expressions are divided into

    common regexps and extended regexps

    Linux+ Guide to Linux Certification, 3e 26

  • Linux+ Guide to Linux Certification, 3e 27

    Table 3-4: Regular expressions

  • The grep Command grep (global regular expression print)

    command: displays lines in a text filethat match common regexps

    egrep command: displays lines in a textfile that match extended regexps Can be written as grep -E

    fgrep command: does not interpret anyregular expressions Returns results much faster than egrep Can be written as grep -F

    grep (global regular expression print)command: displays lines in a text filethat match common regexps

    egrep command: displays lines in a textfile that match extended regexps Can be written as grep -E

    fgrep command: does not interpret anyregular expressions Returns results much faster than egrep Can be written as grep -F

    Linux+ Guide to Linux Certification, 3e 28

  • The grep Command (continued) grep requires two arguments Text to search for

    Can use regular expressions Files in which to search

    grep is case sensitive For case-insensitive search, use i option

    grep matches patterns of text, ignoringdivision into words To search only for occurrences of a word,

    surround it by space characters

    grep requires two arguments Text to search for

    Can use regular expressions Files in which to search

    grep is case sensitive For case-insensitive search, use i option

    grep matches patterns of text, ignoringdivision into words To search only for occurrences of a word,

    surround it by space characters

    Linux+ Guide to Linux Certification, 3e 29

  • 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 notrelated to inserting text

    Insert mode: Inserts text, but nothing else User environment is customizable

    One of the oldest and most popular text editorsfor 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, 3e 30

  • Editing Text Files: The vi Editor(continued)

    Linux+ Guide to Linux Certification, 3e 31

    Table 3-5: Common keyboard keysused to change to and from insert mode

  • Editing Text Files: The vi Editor(continued)

    32Linux+ Guide to Linux Certification, 3e

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

  • Editing Text Files: The vi Editor(continued)

    33Linux+ Guide to Linux Certification, 3e

    Table 3-6 (continued): Key combinationscommonly used in command mode

  • Editing Text Files: The vi Editor(continued)

    34Linux+ Guide to Linux Certification, 3e

    Table 3-6 (continued): Key combinationscommonly used in command mode

  • Editing Text Files: The vi Editor(continued)

    Linux+ Guide to Linux Certification, 3e 35

    Table 3-7: Key combinations commonly used at thecommand mode : prompt

  • Other Common Text Editors Emacs (Editor MACroS) editor: comparable

    functionality to vi Ctrl key combinations to perform special

    functions Supports LISP (LISt Processing) artificial

    intelligence programming language Emacs editor is not easy to use

    Must memorize key combination Emacs can be run in a GUI environment to

    get a graphical version of the editor Much easier to use; icons replace key

    combinations

    Emacs (Editor MACroS) editor: comparablefunctionality to vi Ctrl key combinations to perform special

    functions Supports LISP (LISt Processing) artificial

    intelligence programming language Emacs editor is not easy to use

    Must memorize key combination Emacs can be run in a GUI environment to

    get a graphical version of the editor Much easier to use; icons replace key

    combinations

    Linux+ Guide to Linux Certification, 3e 36

  • Other Common Text Editors(continued)

    Linux+ Guide to Linux Certification, 3e 37

    Table 3-8: Keyboard functions commonlyused in the GNU Emacs editor

  • Other Common Text Editors(continued)

    Linux+ Guide to Linux Certification, 3e 38

    Figure 3-3: A graphical Emacs session

  • Other Common Text Editors(continued) Nano editor: text editor that uses Ctrl key

    combinations for performing functions Based on the pine UNIX editor Ctrl key combinations listed at the bottom of the

    screen Very basic and easy-to-use Used by Linux administrators to modify files

    when advanced functionality is not needed

    Nano editor: text editor that uses Ctrl keycombinations for performing functions Based on the pine UNIX editor Ctrl key combinations listed at the bottom of the

    screen Very basic and easy-to-use Used by Linux administrators to modify files

    when advanced functionality is not needed

    Linux+ Guide to Linux Certification, 3e 39

  • Other Common Text Editors(continued) gedit editor: a graphical text editor

    functional in a GUI environment Does not have advanced functionality like vi

    and Emacs Easiest editor to use Functionality is analogous to the Windows

    Wordpad and Notepad editors

    gedit editor: a graphical text editorfunctional in a GUI environment Does not have advanced functionality like vi

    and Emacs Easiest editor to use Functionality is analogous to the Windows

    Wordpad and Notepad editors

    Linux+ Guide to Linux Certification, 3e 40

  • Other Common Text Editors(continued)

    Linux+ Guide to Linux Certification, 3e 41

    Figure 3-4: The gedit text editor

  • Summary The Linux filesystem is arranged

    hierarchically using a series of directoriesto store files

    Location of directories and files can bedescribed using absolute or relativepathnames

    Linux filesystem can contain many types offiles 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 to modify views

    The Linux filesystem is arrangedhierarchically using a series of directoriesto store files

    Location of directories and files can bedescribed using absolute or relativepathnames

    Linux filesystem can contain many types offiles 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 to modify views

    Linux+ Guide to Linux Certification, 3e 42

  • Summary (continued) Wildcard metacharacters are special

    keyboard characters can simplify selection of several files when

    using common Linux file commands Text files are the most common file type

    whose contents can be viewed byseveral utilities, such as head, tail, cat,tac, more, and less

    Wildcard metacharacters are specialkeyboard characters can simplify selection of several files when

    using common Linux file commands Text files are the most common file type

    whose contents can be viewed byseveral utilities, such as head, tail, cat,tac, more, and less

    Linux+ Guide to Linux Certification, 3e 43

  • 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 grep vi (vim) is a powerful, bimodal text editor

    that is standard on most UNIX and Linuxsystems

    Regular expression metacharacters can beused to specify certain patterns of text 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 Linuxsystems

    Linux+ Guide to Linux Certification, 3e 44