prev | Version 1107 (Mon Nov 27 20:45:55 2006) | next |
ls
, cp
, and wc
doFigure 3.1: A Shell in Action
sh
, is an ancestor of many of thembash
(the Bourne Again Shell) in this courseCygwin
)Figure 3.2: Operating System
notes.txt
or home.html
.txt
is associated with an editor, and .html
with a web browserFigure 3.3: A Directory Tree
/
C:\home\gvwilson\notes.txt
is different from J:\home\gvwilson\notes.txt
C:\home\gvwilson
as c:/home/gvwilson
/cygdrive/c/home/gvwilson
":"
a special meaning, so Cygwin needed a way to write paths without it…"/"
/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 3.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
data
ls
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 3.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$ 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
.svn
directory is for later$ 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
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
man | 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 3.1: Basic Command-Line Tools |
---|
Exercise 3.1:
Suppose ls
shows you this:
Makefile biography.txt data enrolment.txt programs thesis
What argument(s) will make it print the names in reverse, like this:
thesis programs enrolment.txt data biography.txt Makefile
Exercise 3.2:
What does the command cd ~
do? What about cd ~hpotter
?
Exercise 3.3:
What command will show you the first 10 lines of a file? The first 25? The last 12?
Exercise 3.4:
What do the commands pushd
, popd
,
and dirs
do? Where do their names come from?
Exercise 3.5:
How would you send the file earth.txt
to the
default printer? How would you check it made it (other than
wandering over to the printer and standing there)?
Exercise 3.6:
The instructor wants you to use a hitherto unknown command for manipulating files. How would you get help on this command?
Exercise 3.7:
diff
finds and displays the differences between
two text files. For example, if you modify earth.txt
to
create a new file earth2.txt
that contains:
Name: Earth Period: 365.26 days Inclination: 0.00 degrees Eccentricity: 0.02 Satellites: 1
you can then compare the two files like this:
$ diff earth.txt earth2.txt
3c3
< Inclination: 0.00
---
> Inclination: 0.00 degrees
4a5
> Satellites: 1
(The rather cryptic header "3c3"
means that line 3 of
the first file must be changed to get line 3 of the second;
"4a5"
means that a line is being added after line 4 of the
original file.)
What flag(s) should you give diff
to tell it to
ignore changes that just insert or delete blank lines? What if
you want to ignore changes in case (i.e., treat lowercase and
uppercase letters as the same)?
prev | Copyright © 2005-06 Python Software Foundation. | next |