Chapter 1: Welcome to Linux An intro to UNIX-related operating systems.
intro unix/linux 02
Transcript of intro unix/linux 02
Overview
Lesson 2-Touring Essential
Programs
Overview
Development of UNIX and Linux.
Commands to execute utilities.
Communicating instructions to the shell.
Navigating the file system.
Examining and managing files.
Accessing the programmers manual.
Accessing Internet resources.
Development of UNIX and Linux
UNIX os, developed in 1970s at Bell Laboratories, features:
main program, called kernel, to control CPU and other hardware.
collection of user and system programs called utilities.
structure, called file system, for keeping and locating data on hard drive.
Unix was a multi-user and multi-tasking os
Development of UNIX and Linux
Linus Torvalds wrote a UNIX look-alike operating system called Linux.
The operating system is available for free in its basic form for download, or at a low cost from several distributors.
fundamental programs in Linux employ same code, but different distributors add special features and installation programs.
Some of different flavors of Linux operating system are RedHat, Lindows, SuSe, Mandrake, etc.
Development of UNIX and Linux
Commands to Execute Utilities
Introduction to the shell.
Issuing commands to a shell.
Passing information to a utility.
Listing processes.
Introduction to the Shell
shell: program which displays prompt on screen.
shell reads instructions of user and interprets them to the remainder of the system.
Usually $ sign is the prompt in many systems.
shell processes and executes command keyed in by user.
Issuing Commands to a Shell
Various utilities can be executed from the shell prompt.
whoami utility displays users login name or username on screen.
date utility displays current date and time on screen.
hostname utility display name of system user working on.
Issuing Commands to a Shell
clear utility to clear all text on screen and display the prompt at top of screen or window.
Delete or Ctrl-H to correct errors that occur while entering commands.
who utility to display list of users currently logged on.
Issuing Commands to a Shell
Output of who Command
Issuing Commands to a Shell
port: physical location at back of computer.
Each port has designation- usually begins with tty and number
terminal connected through network uses electronic or pseudo port named pts.
Issuing Commands to a Shell
command/utility keyed in by a user is followed by the ENTER key.
shell interprets ENTER as end of command/utility.
shell starts child process to execute command/utility.
Issuing Commands to a Shell
shell locates path of utility/command and executes it.
output, by default, connected to screen, unless redirect it.
After executing command/utility, it returns command prompt again.
Issuing Commands to a Shell
How the shell works
Passing Information to a Utility
When information passed to a utility, shell runs utility, and passes information that comes after the command to utility.
Information passed to utility called argument.
Arguments provide instructions to utilities.
Multiple arguments can also be passed to a utility.
Passing Information to a Utility
cal program provides users current months calendar.
Multiple arguments can be passed to cal utility.
When two arguments are passed to cal program, the program interprets first argument as month and second as year.
Passing Information to a Utility
look command to locate words in dictionary file that begin with that word, and output all matching words.
look command requires one argument word to locate.
Listing Processes
A process is an instance of a running program code.
ps command to list all current processes, with some info about each process.
output displays process id, port, CPU time, and code process is running.
Listing Processes
aux and ef options used with ps command to display processes running on entire system, including system processes, and list of currently logged on users.
Arguments that begin with minus (-) sign are options.
ps option useful for sys-admin trouble-shooting system.
Communicating Instructions to the
Shell
Every user is given a place, called home directory, to work with and save files.
home directory: default workspace of user.
home directory contains names of files and subdirectories created by and owned by a user.
Communicating Instructions to the
Shell
Working with files.
Redirecting output from a utility.
Determining the role of tokens on command-lines.
Starting a child shell.
Reissuing commands.
Using nicknames for commands.
Working with Files
ls (list) command lists contents of current directorys standard files.
more command displays contents of file one part at a time.
command requires one argument name of the file.
spacebar: display additional text in file displayed by more.
q key can to quit more utility.
wc (word count) utility: count number of lines, words, and characters in file.
command requires one parameter name of the file.
Working with Files
Working with Files
l option used with wc command to only count number of lines in file.
-c option: count characters in file.
-w option: count number of words in file.
Redirecting Output from a Utility
By default, results provided by any utility are displayed on users screen.
Instructions can be given to redirect output of utility to file.
command- redirect output of file: utility > filename.
> is instruction to redirect output to new file
Redirecting Output from a Utility
double redirect (>>): append output of utility to end of existing file
| (pipe) command: redirect output of one utility to another utility.
The argument following the pipeline must be a utility.
Determining the Role of Tokens on Command-Lines
Each word or object on a command-line is called a token.
shell is programmed to read initial token as utility program to run or some action to take
location on command-line determines how shell interprets each token.
Starting a Child Shell
List of Various Shells in UNIX/Linux
Reissuing Commands
!! command or r command: re-execute previously entered command.
!! command works only on csh, tch, or bash shell.
The r command works only on a Korn shell.
The sh shell does not allow user to re-execute previously entered commands.
Reissuing Commands
Up arrow key: display previously entered commands one at a time.
shell keeps track of commands we issue at prompt.
history command: list all commands entered previously, and every command has a number associated with it.
Reissuing Commands
Various Options to Execute Previous Commands
Using Nicknames for Commands
An alias or alternate name used for commands hard to remember.
alias command can list all current aliases.
command unalias alias name can remove an alias.
Using Nicknames for Commands
Command
Shell
alias alias name utility name
Csh and tch
alias alias name=utility name
Bash and ksh
Nicknames for commands in UNIX/Linux
Navigating the File System
arrangement of files and folders in system: file system
pwd (present working directory) command can get location of users home directory
result displays path from root to present working directory
topmost directory: root (identified as /)
ls / command can obtain a list of all files and directories in root directory
Navigating the File System
Navigating the File System
mkdir (make directory) command: create new directory
command requires 1 argument name to give to directory
F option used with ls command to include a / (slash) after all directory names and also to identify other kinds of files.
Navigating the File System
cd command can make directory the current directory.
command requires 1 parameter name of directory to become current directory
cd command: return to home directory. no required parameters
Examining and Managing Files
Find matching text:
A particular word in a file can be located by giving the command /word to be located.
n key can locate next instance of same word in file.
b key can be used to move one screen backwards.
Examining and Managing Files
head utility: read first 10 lines of file
tail utility: view last 10 lines of file
Both utilities require 1 argument name of file to read
number of lines to read can be passed as argument to utilities.
Examining and Managing Files
cat utility: view entire contents of file
utility requires 1 argument name of file to read.
utility is preferable when file small
Examining and Managing Files
Copy files:
cp command: make copy of existing file, as well as copy files to another subdirectory.
2 arguments are required to duplicate file name of existing file and name to give duplicated file.
arguments required to copy file to another subdirectory are name of file to copy and target directory
Examining and Managing Files
Removing files:
rm command: delete file
command requires 1 argument name of file to delete
Examining and Managing Files
Removing files (cont):
rm command does its work and displays prompt. It displays no message.
-i option: ask for confirmation before deleting any filenames listed as an argument.
command also accepts multiple file names as arguments.
Examining and Managing Files
Renaming files:
mv command: rename files, as well as move files from one location to another.
2 arguments are required while renaming files current name of file and new name to give file
arguments required for moving files name of files to move and destination directory
Examining and Managing Files
Deciphering utility error messages:
Error messages due to failure of utility are shown in screen by default.
Every process has "output door", where it writes output, and an error door, where it writes error messages.
By default, "error door" connected to screen unless we redirect it.
Examining and Managing Files
Printing file:
lp or lpr command: print file
command requires 1 argument name of file to print.
P option with lpr command, and -d option with the lp command, can specify name of printer to use
Accessing the Programmers Manual
UNIX and Linux systems include extensive collection of powerful utility programs, system features, application languages, and support libraries.
The UNIX programmers manual provides info needed to employ exact syntax of a particular option or command format for a utility.
Accessing the Programmers Manual
manual contains detailed documentation on use and function of utility programs, application programs, and libraries.
manual also contains info on UNIX system files and system programming libraries.
includes supplementary info on related special files and commands for each entry.
Accessing the Programmers Manual
man command: provide online manual entry for utility or command
command requires 1 argument name of utility or command
man k command: search manual pages descriptions for keywords.
Accessing Internet Resources
Internet includes many useful sites that provide info on:
Recent news in Linux world (www.linux.org/www.linux.com).
Interactive Web tutorials
Recent software updates and Linux code documentation.
Summary
shell: process that interprets commands entered by user
Each word or object on command-line: token
All shells, except for sh, allow users to create alias names for commands
file system: collection of files and folders
Summary
We can work on many utilities, print files, and access system folders from a shell.
Files can be printed from shell prompt.
Online manual pages provide detailed description of system utilities, files, and functionalities.
Internet includes useful sites that provide info on various aspects of UNIX and Linux.