330 likes | 498 Views
Agenda. Chapter 1: Linux (Unix) Features Commands (Chapters 2 & 3) Command Structure / Command line editing man, passwd, cal, date, whereis, which Working with Files: file, cat, more, less, grep, head, tail, cp, mv, ls sort, uniq, diff Communicating with Users
E N D
Agenda • Chapter 1: Linux (Unix) Features • Commands (Chapters 2 & 3) • Command Structure / Command line editing • man, passwd, cal, date, whereis, which • Working with Files: • file, cat, more, less, grep, head, tail, cp, mv, ls • sort, uniq, diff • Communicating with Users • who, talk, write, mesg, finger
Unix Structure • The Linux operating system can be visualized in terms of layers: • Unix Kernel • controls the computer resources and schedules jobs • Shell • acts as a command interpreter that acts as an interface between users and the operating system • Utilities (Commands) • comprehensive set of utilities that are universally required by Unix administrators & users. Utilities are often referred to as commands
Linux Structure Calendar systems Compilers Mail & message facilities Inventorycontrol systems Hardware Interpreters Formatters Linux Kernel Database Mgmt System Spreadsheet applications The shell & other basic utilities Editors Word processors
Utilities (Commands) • For the remainder of this course, utilities and commands are considered the same. • Linux commands are usually typed in lowercase followed by an argument (or arguments) • Pressing ENTER or RETURN signals that you have completed giving an instruction and that you are ready for the OS to execute the command or respond to your message
Linux (Unix) Command Format • command [arg 1] [arg 2] … [arg n] • An argument is a filename, string or text, or some other object that a command acts upon • An option is also an argument that modifies the effect of a command • A space, a number of spaces, or a tab can be used to separate command from argument, or separate arguments.
Correcting Mistakes • You can correct mis-typed command prior to pressing ENTER or RETURN • Erase Characters • Backspace or CTRL-Backspace or CTRL-h • Delete a Word • CTRL-w • Delete an Entire Line • CTRL-u
Correcting Mistakes • Aborting Program Execution • DELETE or CTRL-c • Recalling Previous Commands • Depends on shell & .profile setup • Phobos (check .profile for VISUAL variable): • if VISUAL=vi <ESC><K> (K - up, J - down) • if VISUAL=emacs <CTRL><P> • Gothic: • Up arrow , Down arrow
man • A comprehensive online manual for common UNIX commands • format: • man [options] command • Options: • -k provides short (one-line) explanation relating to the commands matching the character string • eg. man -k mkdir
passwd • Used to change existing password • format: • passwd [options] • Options: • -f changes the user information accessed by the finger command
cal • Used to display a calendar • Format: • cal [month] [year](calendar for specified month & year) • cal(displays calendar for current month) • eg. cal 12 2000 • (displays calendar month of December Year 2000)
date • Used to display or set the time & date • Format: • date [option] [+format] • +format argument specifies format of display • After the + sign, can specify (within quotes) text as well as % followed by a field descriptor to indicate how date will be displayed
date • Popular Field Descriptors: • %A Full Weekday name %d Number of day • %B Full month name %m Number of month • %y Last 2 digits of year %Y 4-digit-year • % I Hour %H Hour (Military time) • %M Minutes %S Seconds • %n New Line %r h:m:s with am or pm • eg. date +”Today is %A” (note no space between + and “) • %nis used to advance to the next line
whereis / which • whereis is a utility thatlists all directory paths that contains command or program • For Example: whereis mv • which is a utility that lists only the directory path that the shell will run the command or program (used to help avoid confusion if more that 1 command but perform differently. Example: which mv
Working with Files • file, cat, more, less • grep, head, tail • cp, mv, ls • sort, uniq, diff
file • Used to classify the type of file: ASCII (text) or executable (binary) • Format: • file [options] file-list
cat • Used to combine contents multiple files (“catenate” means to join together). Can be used to display contents of one file • format: • cat [options] [file-list] • *Refer to on-line manual regarding options for cat command
more • Displays a file, one screenful (spacebar) at a time or scroll one line at a time (RETURN) • format: • more [options] [file-list] • Options: • -d prompts user to continue at bottom of screen • note: when searching for text within more process, • user can type k/pattern? ENTER to initiate text search. In addition u for page up, d for down (can also use numbers to indicate amount of movement)
less • Less is a program similar to more, but which allows backward movement in the file as well as forward movement (more movement options than more) • Format: • less [options] [file-list] • Please refer to online manual for movement options
grep • Used to search for a pattern which is stored in a file or files. • Format: • grep [options] pattern [file-list] • Options: • -c displays # of lines that contains a match • -i ignores case sensitivity • -n displays line number of file that contains a match • -l displays only name of file that contains a match
head • Display the beginning lines of a file • format: • head [-number] [file-list] • * “-number” indicates the number of lines (from the beginning of the file) that you want to have displayed
tail • Displays the tail or ending lines of a file • format: • tail [-number] [+number] [options] [file] • * “-number” indicates the number of lines (from the bottom of the file) that you want to have displayed. “+number” indicates line number to display until end (tail) of file
cp • Used to copy one or more files • format: • cp [options] sourcefile destinationfile • Options: • -r subdirectories & contents are copied • -i prompts user to overwrite existing file
mv • Used to move or rename files • format: • mv [options] oldfilename newfilename • mv [options] existingfile-list directory • mv [options] existingdirectory newdirectory • Options: • -i prompts user to overwrite existing file
ls • Used to display information regarding a file or directory • format: • ls [options] [file-list] • Options: • -a short display of all files (incl. hidden files) • -l detailed display of files (excl. hidden files) • -al detailed display of all files • -F displays / after directory, * after executable file
sort • Used to sort or merge files. Particularly useful as a filter to sort standard input. • Format: • sort [options] [field-specifier-list][file-list] • Examples • sort output.txt • who | sort | more • ls | sort > listing.txt
uniq • Used to display lines from a file that are unique. Used after a sort, uniq will only display total “unique” lines of text • uniq [options] [inputfile] [outputfile] • Options: • -c preceed line with # of occurrence line in input file • -d display only lines that are repeated-u display only lines that are not repeated
diff • Displays the differences between two files. Provides instructions as to editing steps to make files identical • diff [options] [file1] [file2]diff [options] [directory1] [directory2] • Options: • -b ignore blanks
Communicating with Others • who • talk • write • mesg • finger
who • Used to display names of users logged into system • Format: • who [options] • whoorwho am iorwhoami • Options: • -H displays head above user information • -i displays # of minutes user was idle • -T displays message reception status
talk / write • talk allows user to conduct a two-way text-based conversation. To initiate talk you type: talk phobos_user_id (use who -T to determine if user is receiving messages) • writeis used to send a message to another user. To send a message, type:write phobos_user_id (Mainly used to broadcast a message but can be used to chat - user who -T to check mesg status first)
mesg • Used to “turn on” or “turn-off” reception of messages from other users. • To turn on message reception status, type:mesg y <ENTER> • To turn-off message reception status, type:mesg n <ENTER>
finger • Used to display user names and related information • format: • finger [options] [user-list] • Options: • -l displays detailed information of all users • -m matches names specified from user-list • -q displays short report of users logged on • -s displays a short report for each user incl.name
finger • Interesting point: • finger utility will display contents in file “.plan” and “.project” in the user’s home directory. • These files are useful to provide additional information about the user • eg. finger msaul (In phobos) • finger jankul (In phobos) • Note: you need to set the file permissons to allow group & others to read file!