Moshe Zadka <[EMAIL PROTECTED]> writes:
> I thought I'd post the topics I'm going to talk about tommorow, and see
> what everybody think:
>
> * basic redirection: ls > results, less < HOWTO
Nitpicking: the last one doesn't look a particularly good example
in view of "less HOWTO".
More substantive: don't forget 2>errors, 2>&1, or even 2>/dev/null,
consider "diff <(prog1) <(prog2)".
> * pipes: ls | less, etc.
> * tr: how to upcase, how to delete characters, how to split words
> * grep: regexs for dummies, multi-file grep, -l, -v
Don't dwell too much on regexps - that's advanced. But the basics -
line anchors (^$), character classes ([a-z]), quantifiers - are a
must. Some other options to grep (-[inc]) are useful.
> * sed: -n, -p, s///g?
> * awk: -F, print fields, check book balancing program
Keep to the very basics, consider a dropping of the cheque-book
balancing program in favour of
ls -l | awk '{whatever}'
ps auxww | awk '{whatever}'
E.g. [this brings up a notion of shell functions]
pname ()
{
ps auxw | egrep "$@" | grep -v egrep
}
pnum ()
{
pname $@ | awk '{print $2}'
}
pkill ()
{
kill -9 `pnum $@`
}
Other common and useful examples: find stale files, find large files,
find memory/CPU hogs etc.
> * sh: for file in *.c do;...;done
> if/[
> while
> #! and chmod +x
> * more complex pipelines: tr | sed, ls | grep | awk, etc.
> * find: -name, -o, -exec, -type
find | grep (possibly with xargs), or grep pattern $(find ...)
Looking for files with specific permissions, etc.
Read and eval, especially the former, for basic interaction.
A tidbit I find pretty useful might serve as an example
illustrating many points:
# search for directories containing pattern:
# first call cdsload, then `cds pattern`
# (From: Marc Ewing <[EMAIL PROTECTED]>)
cds() {
if [ $# -ne 1 ]; then
echo "usage: cds pattern"
return
fi
set "foo" `fgrep $1 $HOME/.dirs`
if [ $# -eq 1 ]; then
echo "No matches"
elif [ $# -eq 2 ]; then
cd $2
else
shift
for x in $@; do
echo $x
done | nl -n ln
echo -n "Number: "
read C
if [ "$C" = "0" -o -z "$C" ]; then
return
fi
eval D="\${$C}"
if [ -n "$D" ]; then
echo $D
cd $D
fi
fi
}
# cdsload is run through crontab every night at 2 am
cdsload() { find / -xdev -type d > $HOME/.dirs ; }
> * Python scripting:
<snip>
> I've got 2*45 minutes. Anyone think I've got too much material/too little
> material?
Not a flame, and with all the respect due to python and your
love for it: skip it. Stick to the shell which is what is of immediate
importance, and is at least a bit familiar from the basic system
navigation. You won't be able to scratch the surface in the time
alotted, and it's a whole new language, easy as it might be to learn.
You already have bash, awk and sed. Just too much, IMHO. You have more
than enough for 2*45 min.
Hope it helps.
--
Oleg Goldshmidt <[EMAIL PROTECTED]>
=================================================================
To unsubscribe, send mail to [EMAIL PROTECTED] with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail [EMAIL PROTECTED]