More UNIX
- Unix pipeline
-
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.
Most common use is inside a shell script.
Use backquotes to capture output into a variable to use later.
x=`date`
echo "Current date is $x"
-
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
Filename completion
Start typing filename, hit special key to complete it.
- 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
- Solaris - Esc
ps See what processes are running
kill (process id) Terminate some of your processes
kill -KILL (pid) Definite kill
kill -1 Kill all my processes
PPID parent process of this process
xkill & Kill the next thing I click on
nice Run something at low priority deliberately
time Time a run of some program
Display of processes
- Linux command line
- Linux GUI:
- Windows:
Task Manager
- Explanation of some of the data returned:
ps in DCU
- Login on lab PCs
- ssh to student.computing.dcu.ie
-
Shared CPU with other users.
-
student.computing.dcu.ie
is a
Linux cluster,
so some users have their own CPU, others are on shared CPUs,
by chance.
- To see other people's processes:
ps -Af
-A all processes
Chrome from GUI:
- Launch Chrome from the Linux GUI.
- In command-line, type ps
- Chrome is not in the list of processes. Why not?
- How do you make a list of processes that includes Chrome?
Chrome from command-line:
- Launch Chrome from command-line:
google-chrome &
- ps now shows Chrome
- It actually shows a program called "chrome" running, not "google-chrome".
- So what is google-chrome?
Type:
which google-chrome
- Follow the trail of shortcuts to find the actual program.
- The program is a shell script. Look inside it to find where "chrome" is and how it is launched.
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.
- If tools cannot do it alone, you can assemble a program to do it.
"Program" may be just one line long.
- 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.
(Or for a thing you want to do now
for which a command-based approach is not appropriate.)
- If it is not in the pre-defined tasks and menus, then you can't do it.
You cannot assemble a program to do it.
- High-noise.
rm all my files - dialog box comes up.
Are you sure? OK.
(This dialog makes no sense in Unix - where a program, not a human user, might be issuing the command to rm files.)
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 on Windows.
And now,
Linux shell on Windows.
- 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.
From
xkcd.