More UNIX
Very powerful features.
-
Pipes - Send output of one program to input of other.
e.g. Search for all lines in the file that contain "DCU" in any case,
except those containing "Computing" in any case,
and sort the remaining lines:
cat file | grep -i dcu | grep -iv computing | sort
-
Backquotes - Capture the output of a program as a string:
echo Current directory is `pwd` and date is `date`
-
Redirection - Read input from a file, send output to a file.
prog < inputfile > outputfile
cat file | grep -i student > studentlist
cat file | grep -i staff > stafflist
All these are the same:
grep string file
grep string < file
cat file | grep string
-
Append:
cat morestuff >> studentlist
- Unix pipeline
Filename completion
Start typing filename, hit special key to complete it.
- DCU Solaris - Esc
- DCU Linux - Tab
- If typing command - will search whole PATH for matches
- If just listing a file - will only search current dir
- If more than one choice - hit Tab twice to show
h history of recent commands (numbered)
!n replay command number n
!string replay last command beginning with string
!! last command
examples
!6 | sort
!ls | grep -v html
ps See what processes are running
kill (process id) Terminate some of your processes
kill -1 All my processes
kill -KILL (pid) Definite kill
xkill & Kill the next thing I click on
nice Run something at low priority deliberately
time Time a run of some program
- DCU Linux:
- Windows:
Task Manager
- Explanation of some of the data returned:
-
In DCU labs, you each have your own CPU and memory,
sharing a central filesystem.
So "ps" will show that the only processes running
on the client machine
are yours and the Operating System's.
However try ps -ef
when you login remotely:
ssh student.computing.dcu.ie
- shared CPU with other users.
(Actually
student.computing.dcu.ie
is a
Linux cluster,
so some users have their own CPU, others are on shared CPUs,
by chance.)
Interrupts
Usage seems to vary on different variants of UNIX and Linux.
You may get something like:
Ctrl-S Pause
Ctrl-C Interrupt
Ctrl-D Kill, Logout
Ctrl-Z EOF
q exit man, more
A computer for programmers.
- Unix philosophy
- Provide lots of tools. String together tools with Shell logic, pipes,
redirection.
- all lower case - fast typing,
don't have to hit Shift key
- short command names
- fast typing
- Silence, "low-noise environment".
rm all my files, and it just does it. Doesn't even display a message
saying they have been removed.
- Note that backquotes would be useless
if all programs displayed lots of informational messages as they executed.
- Often an explicit prog -v "verbose" option
if you want to see informational messages as it executes.
But this is normally not the default.
GUI Philosophy
A computer for non-programmers.
- If not in the pre-installed menus, then hard luck. You can't do it.
- High-noise.
rm all my files - dialog box comes up.
Are you sure? OK.
Note that user interface people say these dialogs are often ignored.
From
Donald Norman,
The Psychology of Everyday Things,
1988, Ch.5:
Human - Delete all my most important files.
System - Are you sure?
Human - Yes Yes.
System - Are you really sure?
Human - Yes Yes.
System - All your most important files deleted.
Human - Oh damnit.
|
Compare with UNIX:
Human - Delete all my most important files.
System - (Silence.)
Human - Oh damnit.
|
Command-line on Mac / Windows
- Windows always had
DOS command-line, and still does.
But for many years it was neglected,
not as powerful as UNIX command-line.
People who liked command lines tended to migrate to UNIX/Linux.
Recently, though, more powerful command shells have been introduced.
- Mac for years had no command-line at all.
But now has UNIX command-line.
Typical modern Mac has powerful UNIX command-line
with bash, csh.