2440:145 Operating Systems The University of Akron Dept of Business Technology

Study Guide #2 Summit College Computer Information Systems

Common UNIX/Linux Supported Editors

·  Some of the UNIX supported editors include:

o  ed – the original line editor.

o  ex – a more sophisticated superset of the ed editor.

o  vi – a visual screen editor

o  emacs – a powerful public domain screen editor which provides macros, programming tools, customization and several keyboard shortcuts

o  pico or nano – a simple editor which includes onscreen information the Control key sequences

o  joe – another simple editor with includes onscreen command information

The vi Editor

·  The two versions of the vi editor are the:

o  view Editor – has read-only flag set in it. Useful for files not meant to be modified.

o  vedit Editor – has several flags set in it. Intended for beginners to make it easier to use vi.

·  The two basic modes of operation in vi are:

Command (edit) mode – the default mode when you enter the vi editor. Key entries are interpreted as commands. Certain commands start with the colon (:), forward slash (/), or question mark (?).

o  Text Input mode – the keyboard becomes your typewriter. Input is not interpreted as a command.

Basic vi Commands

·  vi – access to the vi editor

·  :q – cancels an editing session

·  :q! – cancels an editing session and exits the vi editor without saving

·  :w – saves a file and continues working

·  :wq – saves changes to a disk and exits the vi editor. Can also use ZZ

·  :r – reads text from one file, and adds it to another

·  :! – runs shell commands while in the vi editor. E.g., :! date (shows the date/time), :!r ! cal 2010 (reads the calendar of 2010 into the current file

vi Cursor Movements

·  h – moves the cursor position one space to the left. Can also be accomplished with [Left Arrow]

·  j – moves the cursor position one line down. Can also be accomplished with [Down Arrow]

·  k – moves the cursor position one line up. Can also be accomplished with [Up Arrow]

·  l – moves the cursor position one space to the right. Can also be accomplished with [Right Arrow]

·  0 (zero) – moves the cursor position to the beginning of the current line

·  $ – moves the cursor position to the end of the current line

·  w – moves the cursor position forward one word (to the beginning of the word)

·  e – moves the cursor position forward one word or to the end of the current word

·  b – moves the cursor position backward one word or to the beginning of the current word

·  [Ctrl+d] or [Ctrl+f] – moves the cursor down toward the end of the file 12 or 24 lines respectively

·  [Ctrl+u] or [Ctrl+b] – moves the cursor up toward the beginning of the file 12 or 24 lines respectively

·  G – moves the cursor to a specified line number or end of a file. E.g. 50G (moves cursor to line 50)

·  [Ctrl+g] – checks the line number of the current line

vi Text Input Mode

·  i – inserts text before the character the cursor is on

·  I – inserts text at the beginning of the current line

·  a – appends text after the character the cursor is on

·  A – appends text after the last character of the current line

·  o – opens a blank line below the current line and places the cursor at the beginning of the new line

·  O – opens a blank line above the current line and places the cursor at the beginning of the new line

vi Text Correction (Editing)

·  x – deletes a specified character

·  d – cuts or deletes a specified character to a buffer

·  dd – deletes the current line to a buffer

·  y – copies or yanks a specified character to a buffer

·  yy – copies or yanks the current line to a buffer

·  p – pastes or puts any text from a buffer by placing the contents below the cursor

·  P – pastes or puts any text from a buffer by placing the contents above the cursor

·  u – undo the most recent change

·  U – undo all changes on the current line

·  r – replaces a character that the cursor is on

·  R – replaces characters starting from the cursor position

·  . (dot) – repeats the last text changes

·  “ – the put operator is used to access the buffer. E.g. “2yy (copy current line to numeric buffer 2), “b3dd (delete/cut next 3 lines to alphabetic buffer b), “8p (pastes text from the numeric buffer 8).

The vi Buffers

·  The two main categories of vi buffers are:

Numbered buffers – Nine temporary buffers from 1 to 9

Alphabetic (Named) buffers – 26 buffers from a through z

vi Text Searches

·  :/ – searches forward for a specified pattern. E.g., :/Linux (searches for the word “Linux”)

·  :? – searches backward for a specified pattern. E.g., :?Linux (searches for the word “Linux”)

UNIX/Linux Shell Variables

·  Variables – named buffers to store specific values to control or customize shell environment. The two types of variables supported by Linux shells are:

Environment variables – used to keep track of essentials system needs usually in .profile file

o  Local variables – user-defined for other tasks by the user

Common UNIX/Linux Shell Environment Commands

·  alias – creates an alias for a command. E.g., alias june=”cal 6 2010”

·  unalias – removes an alias for a command.

·  history – lists all the commands contained in the bash history file

·  echo – displays the specified arguments on the output device

·  set – establishes specific operational conditions in the bash shell or displays the environment variable settings

·  unset – removes an unwanted variable

·  grep – selects lines or rows that match a specified patterns of information within a file or command output. E.g., grep John names.list

·  ps – shows processes on a system. E.g., ps aux

·  kill – ends a process using the process ID (PID)

·  cmp – determines whether two files are identical

·  diff or sdiff – compares and selects differences in two files or directories

·  sort – sorts and merges multiple files in alphabetical order

·  uniq – removes duplicate lines from a sorted text file. E.g., sort data.list | uniq

·  sleep – suspends execution for a specified time (in seconds by default). E.g., sleep 60 ; date

·  tee – send a program output to the screen and in a file at the same time. E.g., ls | tee files.list

·  export – makes a variable an environment variable and exports a specified list of variables to other shells. E.g., export VAR1

·  fc – list, edit, and re-execute commands in the history list. E.g., fc -l

·  nohup – prevents the termination of of the background process when logged out

Linux Local Network Communication Commands

·  write – used for terminal-to-terminal communication among logged on users

·  talk – used for terminal-to-terminal communication among logged on users

·  mesg – used prohibit unwanted write messages (n) or receive them (y). E.g. mesg n

·  wall – used mostly by Linux system administrators to send messages to the system users

·  news – used to lookup latest news in the system. Used by systems administrators to provide latest news

·  mail/mailx – provides electronic mail system for Linux users

Other Linux Environment Commands

·  du – summarizes the total disk space used by directories/subdirectories on a file system

·  df – reports the total amount of disk space free on a file system

·  finger – displays detailed information on logged on users

·  time – provides information about a command’s computer time (real, user, and system times). E.g. time ls

·  calendar – a reminder service that reads a schedule from a calendar file users creates in the current directory

·  type – provides more information about another command

·  banner – displays a string(usually 10 characters or less) in large letters

·  spell – checks the spelling of a specified document or words entered from the keyboard

Linux Archiving and Compression Commands

·  tar – copies a set of files into a single file using the options -c (create), -f (file), -v (verbose), -x (extract). E.g. tar –cvf archivedfile.tar file1 file2 file3 (to archive 3 files), tar –xvf archived.tar (to extract the archived files)

·  gzip/gunzip – compresses or decompresses files by reducing the file size

·  bzip2/bunzip2 – compresses or decompresses files by reducing the file size

·  compress/uncompress – compresses or decompresses files by reducing the file size

Linux Task Scheduling Commands

·  at – schedules command execution at a later date only once. E.g. at 13:30 Fri sort mylist

·  crontab – uses the cron daemon to execute scheduled periodic commands.

Linux Security Commands

·  passwd – changes user password

·  chmod – changes the file/directory permissions

·  crypt – encrypts and decrypts files usually with a key. E.g. crypt xy < confidential > confidential.cript

Linux Remote Computing Commands

·  ftp – file transfer program that transfers files from one system to another using commands such as open,cd, dir, ls, put/mput, get/mget, close, quit/ bye

·  telnet – remote login program that allows remote login to a server for a server’s resources

·  rcp – remote copy program

·  rsh – remote shell program

·  rlogin – remote login program

Cron

Cron is a daemon that executes scheduled commands. Cron is started automatically from /etc/init.d on entering multi-user runlevels. Cron searches its spool area (/var/spool/cron/crontabs) for crontab files (which are named after accounts in /etc/passwd); crontabs found are loaded into memory. Note that crontabs in this directory should not be accessed directly - the crontab command should be used to access and update them.

Cron also reads /etc/crontab, which is in a slightly different format. Additionally, cron reads the files in /etc/cron.d.

Cron then wakes up every minute, examining all stored crontabs, checking each command to see if it should be run in the current minute. When executing commands, any output is mailed to the owner of the crontab (or to the user named in the MAILTO environment variable in the crontab, if such exists). The children copies of cron running these processes have their name coerced to uppercase, as will be seen in the syslog and ps output.

Additionally, cron checks each minute to see if its spool directory's modtime (or the modtime on /etc/crontab) has changed, and if it has, cron will then examine the modtime on all crontabs and reload those which have changed. Thus cron need not be restarted whenever a crontab file is modified. Note that the crontab(1) command updates the modtime of the spool directory whenever it changes a crontab.

Special considerations exist when the clock is changed by less than 3 hours, for example at the beginning and end of daylight savings time. If the time has moved forwards, those jobs which would have run in the time that was skipped will be run soon after the change. Conversely, if the time has moved backwards by less than 3 hours, those jobs that fall into the repeated time will not be re-run.

Only jobs that run at a particular time (not specified as @hourly, nor with '*' in the hour or minute specifier) are affected. Jobs which are specified with wild cards are run based on the new time immediately.

Clock changes of more than 3 hours are considered to be corrections to the clock, and the new time is used immediately.

In Debian and Redhat cron treats the files in /etc/cron.d as extensions to the /etc/crontab file (they follow the special format of that file, i.e. they include the user field). The intended purpose of this feature is to allow packages that require finer control of their scheduling than the /etc/cron.{daily,weekly,monthly} directories allow to add a crontab file to /etc/cron.d. Such files should be named after the package that supplies them. Files must conform to the same naming convention as used by run-parts: they must consist solely of upper- and lower-case letters, digits, underscores, and hyphens. Like /etc/crontab, the files in the /etc/cron.d directory are monitored for changes.

You should use absolute path names for commands like /bin/ls. This is to insure you call the correct command.

Crontab

Crontab is the program used to install, deinstall or list the tables used to drive the cron daemon in Vixie Cron. Each user can have their own crontab, and though these are files in /var/spool/cron/crontabs, they are not intended to be edited directly.

Each user has their own crontab, and commands in any given crontab will be executed as the user who owns the crontab. Uucp and News will usually have their own crontabs, eliminating the need for explicitly running su as part of a cron command.

Blank lines and leading spaces and tabs are ignored. Lines whose first non-space character is a hash-sign (#) are comments, and are ignored. Note that comments are not allowed on the same line as cron commands, since they will be taken to be part of the command. Similarly, comments are not allowed on the same line as environment variable settings.