670 likes | 908 Views
Exploring interfaces and filesystems. Unit objectives Outline structure of the Linux interface, and roles of the kernel, terminal and shell Enter shell commands, find documentation, use metacharacters, shut down system Learn directory structure, file types, and use wildcards
E N D
Exploring interfaces and filesystems Unit objectives • Outline structure of the Linux interface, and roles of the kernel, terminal and shell • Enter shell commands, find documentation, use metacharacters, shut down system • Learn directory structure, file types, and use wildcards • Display contents of text and binary files • Search text files by using grep, identify common text editors, and use the vi editor
Topic A • Topic A: Linux interfaces • Topic B: Basic shell commands • Topic C: Files and directories • Topic D: Displaying the contents of files • Topic E: Searching and editing text files
Shells, terminals, and the kernel • Kernel • The core component of the OS • Terminal • Screen that allows you to log in • Shell • Runs within the terminal • Interface that accepts commands and passes them to the kernel • BASH Shell (Bourne Again Shell): the default shell continued
Exercise A-1 Discussing terminals and shells
Topic B • Topic A: Linux interfaces • Topic B: Basic shell commands • Topic C: Files and directories • Topic D: Displaying the contents of files • Topic E: Searching and editing text files
Basic Shell Commands • Commands • Indicate name of the program to execute • Options • Letters starting with a dash “-” that alter way the command works • Arguments • Specify the parameters the command works upon
Shell metacharacters • Key combinations that have special meaning in the Linux OS • One of the most commonly used metacharacters is the $ character
Activity B-1 Using shell commands and metacharacters
Getting command help • Manual pages • Commonly referred to as man pages • Documents the command’s function and the syntax it accepts
Activity B-2 Getting help
Activity B-3 Shutting down the system
Topic C • Topic A: Linux interfaces • Topic B: Basic shell commands • Topic C: Files and directories • Topic D: Displaying the contents of files • Topic E: Searching and editing text files
The Linux directory structure • 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 • Home directory • A directory for users to store personal files and information • Each user has a sub-directory
Changing directories • 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 • ~ • 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 • Tab-completion • Fills in the remaining characters of a unique filename or directory name when you press the Tab key
Activity C-1 Logging on and navigating the file structure
File types • Text files • Binary data files • Executable program files • Directory files • Linked files • Special device files • Named pipes and socket files
Filenames • 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
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
Ls –F file type characters • @ Linked file • * Executable file • / Subdirectory • = Socket file • | Named pipe
The file command • File command • Displays detailed information about any file • Works with multiple files • Uses * to include all files in a directory
Hidden files • Hidden files • Files that are not normally displayed with common filesystem commands • represent important configuration files or program directories
ls command options continued
Activity C-2 Examining files and file types
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
Activity A-3 Using wildcard metacharacters
Topic D • Topic A: Linux interfaces • Topic B: Basic shell commands • Topic C: Files and directories • Topic D: Displaying the contents of files • Topic E: Searching and editing text files
Displaying content of text files • 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 • 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 • more command • Displays a text file page-by-page and line-by-line • Gets its name from the pg command once used on UNIX system • less command • Displays a text file page-by-page • Use the cursor keys to navigate the file
Activity D-1 Displaying text file contents
Displaying the contents of binary files • 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
Activity D-2 Displaying binary data
Topic E • Topic A: Linux interfaces • Topic B: Basic shell commands • Topic C: Files and directories • Topic D: Displaying the contents of files • Topic E: Searching and editing text files
Searching for text within files • Regular expressions (regexp) • Special metacharacters used to match patterns of text within text files • Commonly used by many text tool commands such as grep
Regular expressions and wildcards • Regular expressions are interpreted by a text tool program, wildcard metacharacters are interpreted by the shell, • Regular expressions match characters within text files, wildcard metacharacters match characters in filenames or directory names continued
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 continued