770 likes | 934 Views
Unit 3: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
Unit 3: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
Shells, terminals, and the kernel • Kernel • The core component of the OS • An actual file on the HD • Need an interface to interact with kernel • 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
Shells, terminals, and the kernel • One kernel • Multiple shells and terminal sessions can be going at once • Terminals can be run locally or remote across network • Text only commands • Can run the system • Graphical mode • User friendly
Shell Prompts and Guis • Shell Prompts • As root • {root@localhost root}# • As a regular user • {root@localhost user1}$ • GUI • Loaded based on installation and preferences
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
Command Examples Last login: Tue Feb 13 22:43:26 2007 from 192.168.1.4 [epapates@localhost ~]$ finger Login Name Tty Idle Login Time Office Office Phone epapates Elias Papatestas pts/1 21 Feb 13 20:39 (192.168.1.3) epapates Elias Papatestas pts/2 1 Feb 13 22:46 (:0.0) epapates Elias Papatestas pts/3 Feb 13 22:48 (192.168.1.4) [epapates@localhost ~]$ who epapates pts/1 2007-02-13 20:39 (192.168.1.3) epapates pts/2 2007-02-13 22:46 (:0.0) epapates pts/3 2007-02-13 22:48 (192.168.1.4)
Command Examples [epapates@localhost ~]$ w 22:48:34 up 2:53, 3 users, load average: 0.64, 0.42, 0.44 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT epapates pts/1 192.168.1.3 20:39 21:41 1:01 1.08s sshd: epapates epapates pts/2 :0.0 22:46 1:22 1.07s 5.30s gnome-terminal epapates pts/3 192.168.1.4 22:48 1.00s 0.98s 0.31s w [epapates@localhost ~]$ whoami epapates [epapates@localhost ~]$ id uid=500(epapates) gid=500(epapates) groups=500(epapates) context=user_u:system_r:unconfined_t [epapates@localhost ~]$
Shell metacharacters • Key combinations that have special meaning in the Linux OS • $ character • Tells shell that following text refers to a variable • Variable • Information stored in memory • Many pre-defined
Using variables [epapates@localhost ~]$ echo Hi There! Hi There! [epapates@localhost ~]$ echo My shell is $SHELL My shell is /bin/bash [epapates@localhost ~]$
Using Metacharacters • If you need to use a metacharacter, place it in quotes • Echo I need ‘$’2.00 • [epapates@localhost ~]$ echo I need $2.00 • I need .00 • [epapates@localhost ~]$ echo I need '$'2.00 • I need $2.00 • [epapates@localhost ~]$
Activity B-1 • Page 3-8, 3-9 • Examples of basic commands • Examples of metacharacters
Getting command help • Manual pages • Commonly referred to as man pages • Documents the command’s function and the syntax it accepts • Usage • man whoami • Multiple levels • Depending on what type of command
Getting command help • Multiple Names • Lowest page appears • Searching Man pages • Man –k command/apropos command • man –k who • apropos who
Getting command help • Info pages • Less “techie” • Usage • info who • Help command • Used for commands that may not have info or man pages • Usage • help echo
System Shutdown • System writes data from memory to HD • If shutdown happens while system is writing, it can corrupt data • Use shutdown commands to shut down gracefully • Tell everyone to please log off • Can cancel with CTRL-c or shutdown -c • Usage • -h halt • -r reboot • 15 time
The Linux directory structure • Start at root directory • Directory structure doesn’t usually show partition mount points • 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
Paths • Route to location of file or directory • Absolute pathname • Full pathname to a certain file or directory starting from the root directory
Mounting Filesystems • Directories can be in same partition or different • Can make a partition part of the directory structure with the mount command • Mount the hda2 to appear as the home directory
Home directory • Home directory • A directory for users to store personal files and information • Each user has a sub-directory • Located at /home/username
Navigating Filesystem • 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 • If more than one match, system will beep
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
Ls –l file details • File type • Permission list • Important • Link count • Owner • Group • Size • Modified date • filename
Ls –l file details File type Permissions Links Owner Group Size Modified date filename total 143860 -r--r--r-- 1 epapates epapates 35618816 Nov 13 16:06 linux.iso -r-xr-xr-x 1 epapates epapates 111527809 Feb 14 02:56 VMware-workstation-5.5.3-34685.tar.gz
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 • View with –a option from ls command
ls command options continued
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 C 2 and 3 Examining files and file types Using wildcard metacharacters
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