Re: This Month's (Monday's!) Meeting Topic

Tom Hull <[email protected]> Sun, 13 Apr 2003 00:41:12 -0500
Newsgroups gmane.org.user-groups.aclug.presentations
Message-ID <[email protected]>
Tom Hull wrote:
> Jonathan Hall wrote:
>=20
>>Can we secure the meeting room we had for the LDAP presentation? If so,
>>perhaps it would be a good opporitunity to do a "command line"
>>presentation--a hands-on discussion of common shell commands, and basic
>>scripting.
>>
>>I would be happy to present on that topic, altho I can't guarantee that=
 I'd
>>have much of a handout ready.  I think I have a partial one written fro=
m
>>years ago, if I can find that, we can use that.  Otherwise, it will jus=
t
>>depend on my work schedule on Monday whether I have time to put anythin=
g
>>other handout together.  But I can talk off of the top of my head (or o=
ut of
>>my ass) even without a handout :)
>=20
>=20
> I wrote up a rather extensive handout a couple of years ago. Having
> trouble finding a copy here. I think it was on the complete.org aclug
> website. Might be good to start with, either to edit down or ad lib
> off of, if anyone can find a copy. (I'd like to have one myself.)

Still can't find mine, but I found Jeff Schaller's, prepared at the same
time. Enjoy:


 From schaller-5e8rrbeKQCVH4x6Dk/[email protected] Fri Oct 29 21:54:05 1999

This is in a slightly modified form -- I modified it
and printed it out all in one fell swoop, not saving the
copy that I printed.  This has most of what I covered, except
for the crappy ad hoc part about file permissions at the beginning.

Pipes
	- to pass information from one program to another
	- who | grep schaller

Backticks
	- to insert results from one command into another
	- kill -9 `cat /var/run/named.pid`

Wildcards
	- to pick up more than one file
	- ls *.log
	  rm kernel.log.?

Job control
	- manipulate jobs
	- sleep 60 &
	  fg %1
	  ^Z
	  bg

Basics: command vs arguments
	- command is the first word, arguments are the rest
	- command can be a shell built-in, alias, or actual program
	  - actual programs are looked for in your $PATH
	  - echo $PATH | tr ':' '
	    ' | sort -u

Quoting
	- protect arguments from the shell
	- ps aux | grep 'getty console'

Useful commands
	- grep: search for text
		ps aux | grep xterm
		ps aux | grep -v root
		ps aux | grep -c schaller
	- awk: print certain information, others
		ps aux | grep sendmail | awk '{ print $2 }'
		/bin/ls -l | awk '{ SUM +=3D $5 } END {
		  printf "Total Kbytes: %d\n", SUM/1024}'
	- tr: translate characters
		echo ABC | tr '[A-Z]' '[a-z]'
		echo ABC | tr '[:upper:]' '[:lower:]'
	- sed: stream editor
		ps aux | sed 's/schaller/root/g'
	- cut: grab certain parts of line(s)
		/bin/ls -l | cut -c1-1
		echo $PATH | cut -d: -f2
	- rm: remove (unlink) files
	    (ls -l file[s]) and look at the number between permission bits
	    and owner -- this is the number of links to the file, typically 1.
		rm /var/www/index.html
	- mv: move files
		mv /var/log/kernel.log /tmp/kernel.log
	- echo: prints its arguments
		echo /bin/ls
		echo /bin/l*
		echo $PATH
	- ln: make links (soft or hard)
		ln -s /usr/tmp /tmp
		ln resume.html index.html
	    ( ls -i resume.html index.html )

Shell scripts
	- files containing commands to be run
	  #!/bin/sh
	  ls

		chmod u+x file.sh


--=20
/*
  *  Tom Hull * thull2 at cox.net * http://www.tomhull.com/
  */