April 24, 2010: We are pleased to announce that Version 4 of this course is now under development. For updates and an early peek at the content, please check out the Software Carpentry blog at http://www.software-carpentry.org/blog/.
A shell is a command line interpreter that is the interface between the user and the Operating System
ls, cp, and wc do
Figure 9.1: A Shell in Action
sh, is an ancestor of many of them
bash (the Bourne Again Shell) in this course
shThe operating system is the low level software that runs everything
Figure 9.2: Operating System
notes.txt or home.html.txt is associated with an editor, and .html with a web browser
Figure 9.3: A Directory Tree
/
C:\home\gvwilson\notes.txt is different from J:\home\gvwilson\notes.txtC:\home\gvwilson as c:/home/gvwilson/cygdrive/c/home/gvwilson
":" a special meaning, so Cygwin needed a way to write paths without it...A path is a description of how to find something in a file system
"/"/home/hpotter is Harry Potter's home directory/courses/swc/web/lec/shell.html is this file/courses/swc, the relative path to this file is web/lec/shell.html"." (pronounced "dot") is the current directory".." (pronounced "dot dot") is the directory one level up
/courses/swc/data, .. is /courses/swc/courses/swc/data/elements, .. is /courses/swc/data
Figure 9.4: Parent Directories
pwd (short for "print working directory") to find out where you are
$ pwd
/home/hpotter/swc
ls (for "listing") to see what's in the current directory$ ls
LICENSE.txt conf data docs index.swc license.swc print.css swc.css tests Makefile config.mk depend.mk img lec press sites swc.dtd util
data directory, type ls data$ ls data
bio elements haiku.txt morse.txt pdb solarsystem.txt
cd data to "go into" data
datals on its owncd .. to go back to where you started$ cd data $ pwd
/home/hpotter/swc/data
$ ls
bio elements haiku.txt morse.txt pdb solarsystem.txt
$ cd .. $ pwd
/home/hpotter/swc
ls, the OS:
Figure 9.5: Running a Program
ls produce more informative output by giving it some flags
"-", as in "-c" or "-l"$ ls -F
LICENSE.txt conf/ data/ docs/ index.swc license.swc print.css swc.css tests/ Makefile config.mk depend.mk img/ lec/ press/ sites/ swc.dtd util/
.
ls doesn't show things whose names begin with .
. and .. don't always show up.svn directory is for later$ ls -a
. .svn Makefile config.mk depend.mk img lec press sites swc.dtd util .. LICENSE.txt conf data docs index.swc license.swc print.css swc.css tests
$ ls -a -F
. .svn/ Makefile config.mk depend.mk img/ lec/ press/ sites/ swc.dtd util/ .. LICENSE.txt conf/ data/ docs/ index.swc license.swc print.css swc.css tests/
$ mkdir tmp
-v ("verbose") would tell mkdir to print a confirmation message)$ cd tmp $ ls
earth.txt with the following contents:Name: Earth Period: 365.26 days Inclination: 0.00 Eccentricity: 0.02
Name: Venus Period: 224.70 days Inclination: 3.39 Eccentricity: 0.01
venus.txt is to copy earth.txt and edit it$ cp earth.txt venus.txt $ edit venus.txt $ ls -t
venus.txt earth.txt
-t tells ls to list by modification time, instead of alphabeticallycat (short for "concatenate")
$ cat venus.txt
Name: Venus Period: 224.70 days Inclination: 3.39 Eccentricity: 0.01
ls -l ("-l" meaning "long form")$ ls -l
total 2 -rwxr-xr-x 1 gvwilson None 73 Jan 4 15:58 earth.txt -rwxr-xr-x 1 gvwilson None 73 Jan 4 15:58 venus.txt
wc (for "word count")$ wc earth.txt venus.txt
4 9 73 earth.txt 4 9 73 venus.txt 8 18 146 total
set or envat the command prompt to get a listing:$ set
BASH=/usr/bin/bash BASH_VERSION='2.05b.0(1)-release' COLUMNS=120 HISTFILE=/home/.bash_history HISTFILESIZE=500 HISTSIZE=500 HOME=/home/rweasley HOSTNAME=hogwarts HOSTTYPE=i686 LINES=60 NUMBER_OF_PROCESSORS=1 OSTYPE=cygwin PATH='/usr/local/bin:/usr/bin:/bin:/Python24:/home/rweasley/bin' PWD=/home/rweasley SHELL=/bin/bash UID=1003 USER=rweasley
"$" in front of its name
ls $HOME is the same as ls /home/rweasley (if you're Ron Weasley)echo command to print out a variable's value$ echo $HOME
/cygdrive/c/home/rweasley
echo $HOME, and not just $HOME?The default set of environment variables can be quite different on different machines and operating systems, but here are the most commonly used ones:
| Name | Typical Value | Notes |
|---|---|---|
EDITOR |
/bin/edit |
Preferred editor |
HOME |
/home/rweasley |
The current user's home directory |
HOMEDRIVE |
C: |
The current user's home drive (Windows only) |
PATH |
"/home/rweasley/bin:/usr/local/bin:/usr/bin:/bin:/Python24/" |
Where to look for programs |
PWD |
/home/rweasley/swc/lec |
Present working directory (sometimes CWD, for current working directory) |
SHELL |
/bin/bash |
What shell is being run |
Table 9.1: Shell Variables
$ VILLAIN="Lord Voldemort"
$ VILLAIN="Lord Voldemort" $ bash $ echo $VILLAIN
$ exit
Figure 9.6: Setting a Variable Without Exporting It
$ VILLAIN="Lord Voldemort" $ export VILLAIN $ bash $ echo $VILLAIN
Lord Voldemort
$ exit
Figure 9.7: Exporting a Variable's Value
$ export VILLAIN="Lord Voldemort" $ bash $ echo $VILLAIN - Lord Voldemort $ exit
PATH environment variables defines the shell's search pathbroom, the shell:
$PATH into components to get a list of directories
PATH is /home/rweasley/bin:/usr/local/bin:/usr/bin:/bin:/Python24/usr/local/bin/broom and /home/rweasley/bin/broom exist/home/rweasley/bin/broom will be run when you type broom at the command prompt/bin, /usr/bin: core tools like ls
/usr/local/bin: optional (but common) tools, like the gcc C compiler$HOME/bin: tools you have built for yourself
$HOME is your home directory. (the current working directory) in your path
whatever, instead of ./whateverman |
Documentation for commands. |
cat |
Concatenate and display text files. |
cd |
Change working directory. |
clear |
Clear the screen. |
cp |
Copy files and directories. |
date |
Display the current date and time. |
diff |
Show differences between two text files. |
echo |
Print arguments. |
head |
Display the first few lines of a file. |
ls |
List files and directories. |
mkdir |
Make directories. |
more |
Page through a text file. |
mv |
Move (rename) files and directories. |
od |
Display the bytes in a file. |
passwd |
Change your password. |
pwd |
Print current working directory. |
rm |
Remove files. |
rmdir |
Remove directories. |
sort |
Sort lines. |
tail |
Display the last few lines of a file. |
uniq |
Remove adjacent duplicate lines. |
wc |
Count lines, words, and characters in a file. |
Table 9.2: Basic Command-Line Tools
Copyright © 2005-09 Python Software Foundation.
Created Thu Aug 6 21:56:06 2009 UTC