Week 6 summary

02 Oct 2011

We went over operating system concepts and shells, and went over a lot of examples in the Windows command line shell.

Here's a very quick reminder of what we covered about the command line:

  • The command line shell program is called cmd.exe in Windows. To run, you can open the start menu and type cmd, and it will appear. Or you can hit win-r (hold the Windows key and hit r), and then type cmd.

  • All interaction with the command line consists of typing commands followed by zero or more arguments, and then possibly redirecting input or output.

    The behavior of commands can be modified by specifying flags, which for Windows programs usually begin with a /. The /? flag is common to many commands, and will display a help message.

    Basic commands will look like:

    command-name /flag-1 /flag-2 arg-1 
    

    To display help for a command, you can type: command-name /?

  • The command line shell, like all other programs, always has a current directory, or working directory. In the shell, this is the directory you're currently looking at, just like if you had opened a graphical Explorer window to a directory.

  • Navigation

    • dir lists the contents of the working directory.
    • cd changes the working directory.
  • Creation/deletion

    • mkdir creates directories
    • copy and move copy and move files
    • del deletes files (permanently!)
  • Environment variables The shell (as well as other programs) can use environment variables to keep track of common information. The set command lists variables and their values, or can set variables to new values.

  • Other programs

    • You can start any other program by typing its name on the command line. Example: notepad my-text-file.txt.
    • A program must be stored in one of the folders listed in the PATH environment variable in order for the command line to understand its name. To add a new folder (say, for example, C:\Program Files\Notepad++) to the PATH, use:

      set PATH=%PATH%;C:\Program Files\Notepad++
      
  • I/O redirection

    • You can send the output from a command to a file. For example, to save the contents of the working directory to a file, use: dir > file-list.txt
    • You can pipe the output from one command into the input for another. For example, to page through the contents of a very full directory, use: dir C:\Windows\System32 | more
    • You can send the contents of a file as input to a program. For example, this lists all lines in file-list.txt that contain the letters .html: find ".html" < file-list.txt

Some helpful links: