5. Philosophy
Doug McIlroy:
● Write programs that do one thing and do it
well.
● Write programs to work together.
● Write programs to handle text streams,
because that is a universal interface.
6. Let's get started
These slides:
- Slideshare
Use your own shell
or
Go here:
http://bellard.org/jslinux/
7. A brief note about shells
Many flavors
Bourne (sh)
Korn (ksh)
Bourne-again (bash)
C-shell (csh)
tcsh
echo $0
8. How do I get in/out?
login: searchguy
Password:
Authentication successful
Logout
> exit, logout
id, whoami
passwd
10. Exercise
Login to JS shell
1. Who are you logged in as?
2. What is the name of the machine?
3. What is the OS? and version?
4. What dir are you working in?
5. Change dir to /bin
a. Look at a listing of all files in that dir
b. are there any that begin with 'z' (just eyeball it for
now)
17. Exercise
1. Navigate to /etc/ directory
2. Take the file named "passwd"
a. Make 4 copies in /var/tmp/
b. Name them as follows:
i. passwd1, passwd2, passwd3, passwd4
3. Search for the string "daemon" in any one of
the 4 files
a. How many instances did you find?
23. Exercise: Linking
1. Navigate to /var/tmp
2. Create a hardlink to the passwd3 file
3. Create a symlink to the passwd4 file
What do you see?
1. Delete passwd3 and passwd4
What do you notice?
27. Exercise: I/O, Redirection
command arg1 arg2 ... > filename
● cat > io.txt
Unix is great, much better than many other os's
makes me very productive
CONTROL-D
● cat < io.txt
● In /var/tmp merge all passwd* files into one
28. Exercise: Pipes
● Your merged file in /var/tmp
○ find the uniq lines
○ sort the file
○ now let's pipe it!
● sort filename | uniq
● find . -name 'pass*' | xargs grep -i nobody
29. More on pipes...
history | perl -pe 's/^ +[0-9]+//' | sort | uniq -c | sort -nr | head
"Top 200" list of directory sizes (under /dir-name - in KB)
sorted by largest:
du -dk /dir-name | sort -rn | head -200 > report.txt
List of requesting IP's from a web server log, sorted by
most frequent first:
cut -f1 -d access.log | sort | uniq -c | sort -rn
[df: free disk blocks,
du: disk usage]