prev | Draft Version 584 (Thu Dec 1 09:18:41 2005) | next |
command < inputFile
reads from inputFile
instead of from the keyboardcommand > outputFile
writes to outputFile
instead of to the screencommand < inputFile > outputFile
does bothwords.len
$ wc -w *.txt > words.len
words.len
$ ls -t
words.len venus.txt earth.txt
$ cat words.len
4 9 69 earth.txt 4 9 69 venus.txt 3 12 62 words.len 11 30 200 total
cat > junk.txt
cat
reads from the keyboardrm junk.txt
to get rid of the filerm *
unless you're really, really sure that's what you want to do…wc -w *.*
to count the words in some files, then sort -n
to sort numericallywc *.txt > temp sort -n < temp
"|"
wc -w *.* | sort -n
9 earth.txt 9 venus.txt 12 words.len 30 total
wc *.txt | sort -n | head -5 > shortest.files
set
at the command prompt to get a listing:
$ set
ANT_HOME=C:/apache-ant-1.6.2 BASH=/usr/bin/bash COLUMNS=80 COMPUTERNAME=ISHAD HISTFILESIZE=500
"$"
in front of its name"$HOME"
with the current user's home directoryecho
command to print this out$ echo $HOME
/home/gvwilson
echo $HOME
, and not just $HOME
?$ export VARNAME=value
~/.bashrc
"~"
is a shortcut meaning “your home directory”
~/.bashrc
is /home/gvwilson/.bashrc
Name | Typical Value | Notes |
---|---|---|
HOME | /home/gvwilson | The current user's home directory |
HOMEDRIVE | C: | The current user's home drive (Windows only) |
HOSTNAME | "ishad" | This computer's name |
HOSTTYPE | "i686" | What kind of computer this is |
OS | "Windows_NT" | What operating system is running |
PATH | "/home/gvwilson/bin:/usr/local/bin:/usr/bin:/bin:/Python24/" | Where to look for programs |
PWD | /home/gvwilson/swc/lec | Present working directory (sometimes CWD , for current working directory) |
SHELL | /bin/bash | What shell is being run |
TEMP | /tmp | Where to store temporary files |
USER | "gvwilson" | The current user's ID |
PATH
tabulate
, the shell:
$PATH
on colons to get a list of directoriesPATH
is /home/gvwilson/bin:/usr/local/bin:/usr/bin:/bin:/Python24
/usr/local/bin/tabulate
and /home/gvwilson/bin/tabulate
exist/home/gvwilson/bin/tabulate
will be run when you type tabulate
at the command prompt.
in your pathwhatever
, instead of ./whatever
which program_name
, which will tell youPATH
include:
/bin
, /usr/bin
: core tools like ls
/usr/local/bin
: optional (but common) tools, like the gcc
$HOME/bin
: tools you have built for yourself$HOME
means “the user's home directory”~/bin
/cygdrive/c/somewhere
instead of Windows' c:/somewhere
c:/somewhere
would clash with the colons in the PATH
variablec:/cygwin
as the root of its file system/home/aturing
is a synonym for c:/cygwin/home/aturing
man | Documentation for commands. |
cat | Concatenate and display text files. |
cd | Change working directory. |
chmod | Change file and directory permissions. |
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. |
env | Show environment variables. |
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 duplicate lines. |
wc | Count lines, words, and characters in a file. |
which | locate a command |
groups
command will show you which ones you are inls -l
will show all of this informationrwx
triples"-"
rw-rw-r--
means “user and group can read and write; everyone else can read; no one can execute”chmod
chmod u+x something.exe
gives the user execute permission to something.exe
chmod o-r notes.txt
takes away the world's read permission for notes.txt
tools
has permission rwx--x--x
(i.e., owner can do anything, but everyone else only has execute permission), then:
ls tools
, permission is deniedtools/findanswers
, other users can still run itdu | Print the disk space used by files and directories. |
find | Find files that match a pattern. |
grep | Print lines matching a pattern. |
gunzip | Uncompress a file. |
gzip | Compress a file. |
lpr | Send a file to a printer. |
lprm | Remove a print job from a printer's queue. |
lpq | Check the status of a printer's queue. |
ps | Display running processes. |
tar | Archive files. |
which | Find the path to a program. |
who | See who is logged in. |
xargs | Execute a command for each line of input. |
Exercise 5.1:
You're worried your data files can be read by your nemesis, Dr. Evil. How would you check whether or not he can, and if necessary change permissions so only you can read or write the files?
prev | Copyright © 2005, Python Software Foundation. See License for details. | next |