Home

Syllabus

Notes

Homework

Grades


Basic Commands


Basic Commands
        What is Unix
        Logging in
        Command basics
        Various useful commands
        Archaic stuff
        I/O Redirection, Metacharacters, and Pipes
        Customization
        Logging out


Reading: The Unix Programming Environment, Chapter 1

What is Unix

  • Just what makes a system "Unix" anyway?
    • Officially "branded" by SCO?
      • Note that Linux and FreeBSD are not "branded Unix."
    • A timesharing system with certain features?
      • What features?
    • Is it the kernel, or the command line utilities as well?
      • Can you come up with a definition that distinguishes Unix from Windows 2000 with the Cygwin package installed?
    • Geof Allen’s wife uses MacOS X, but never uses the command line. Is she a Unix user?
  • The authors of The Unix Programming Environment allow for various interpretations and say, in essence, if it looks like a duck and you feel like calling it a duck, go ahead and call it a duck.
    • They expect you to figure out from the context what "Unix" means in any particular sentence.
  • Whatever you call it, Unix can be rather intimidating, but an understanding of some fundamental philosophies and familiarity with a handful of commands (i.e. passing this course) will help you tap its power.
    • Remember that Unix was designed by programmers for programmers, so many of its features are there to help programmers.

Logging in

  • Unix is a multiuser system (meaning that many different users may use the same system), so users must identify themselves.
  • Authentication (proving who you are) is done with a login name and a password.
    • Protecting your password is important because it's the "key" to who you are on the computer.
  • After successfully authenticating yourself, some setup is done in the background (using shell scripts, which we'll talk about later in the semester), and you are given a "shell prompt".
    • This is the place where you give Unix commands and get results back
  • Note that we're talking about a text login here. GUI login is a bit different.

Command basics

  • Commands are entered by typing them at the command line.
  • An end of line (entered with the return key) tells Unix (actually your shell) to go ahead and interpret the line of text, and do whatever it says.
  • Simple examples
    • date
      • Shows the current date and time
    • who
      • Shows who is currently logged in
    • last
      • Shows the last number of users to log in
    • who am i
      • Tells you who you are.
        • This is actually useful sometimes!

Various useful commands

(For varying degrees of "useful".)

  • write
    • This command is a simple way to send a message to someone else.
    • Think of it as a 1970s version of instant messaging.
  • man
    • Allows you to read "man pages"
      • The term "man page" refers to the days when the Unix manual was printed, and each command or system call got its own page (or often pages), thus it was a "man page."
      • The same reference was provided in electronic form, and the same name stuck
    • Standard format
    • More reference than tutorial
    • Iterate!
      • Read the man page
      • Try the command
      • Read the man page again, understand a little more
      • Try the command again
      • etc.
    • Use man -k to look for commands
      • Example: man -k edit
    • Use the "See also" section to find other related commands; sort of a primitive hypertext system
  • ls
    • You will use this often, to check on the existence of files and view their metadata (permissions, modification time, etc).
    • If you don't already know it, spend some time to get familiar with the format of ls -l.
  • more or less
    • A couple of nice "view a screen of text at a time" utilities. less is more capable than more.
  • head and tail
    • let you view just the beginning or ending of a file
  • diff
    • Shows you the differences between two files, in a format that seems cryptic until you understand it.
  • echo
    • “Echoes” (prints) the command line to the output output
  • You should be familiar with the commands in Table 1.1 on page 22 of The Unix Programming Environment.

Archaic stuff

  • The Unix Programming Environment discusses the use of the '#' and '@' characters for undoing mistakes in your typing. That is archaic and dates from the days before 101-key keyboards, specifically before the control key was common.
    • Nowdays, typing '#' and '@' probably gives you a '#' or an '@'
  • The book also says you can cancel most commands with the delete or break keys
    • This is probably "^C" on whatever system you're using
      • "^C" is the conventional way to write "control-C", i.e. hold down the control key and type "C".
  • The mail command
    • Pay no attention to what the book says about reading or sending mail
    • Once upon a time, the mail command, as described in the book was the only way to do it.
      • Trust me, you'd rather use pine, elm, mutt, or just about any other mail command
  • news
    • This was a simple way to inform users of things they ought to know
    • That function is now performed by email
    • Do not confuse the news command with "netnews" aka. "usenet"
  • learn
    • Probably doesn't exist
  • ed
    • The Unix Programming Environment describes ed as "universally available, efficient, and effective." Read up on it only to have a laugh at the old-timers who actually had to use ed on a daily basis.
  • pr
    • Use less or more

I/O Redirection, Metacharacters, and Pipes

  • We'll get into each of these topics when we get to Chapter 3
  • It might be worth reading the discussion here in Chapter 1, to get ready for the full discussion in Chapter 3.

Customization

  • The treatment here is very brief, but the things mentioned here, especially stty, are still useful.
  • For some sadistic reason, the computer world has burdened us with two different possible characters coming from the "backspace" key, and you will eventually encounter a system that uses the opposite one from what you're using.
    • The stty erase command is your key to dealing with this
  • The book talks about changing .profile to customize your setup.
    • That is true for the Bourne Shell, and others derived from it
      • Korn Shell (ksh), Bourne-Again Shell (bash), etc.
    • C-shell (csh) and it's derivatives use .login

Logging out

  • You start a Unix session by logging in, you end it by logging out
  • The book says "^D" is the best way to log out.
    • But "exit" and/or "logout" also work, and are preferred by some shells