Slide #1.

Cs288 Intensive Programming in Linux Instructor: C F Yurkoski [email protected] Section web site: https://web.njit.edu/~yurkowsk/cs288.html 6-9-15 1
More slides like this


Slide #2.

6-9-15 2
More slides like this


Slide #3.

Linux access • ssh to afs5.njit.edu • or use putty, etc. 6-9-15 3
More slides like this


Slide #4.

Quiz 1 results • Not yet available 6-9-15 4
More slides like this


Slide #5.

Quiz1 revu 6-9-15 5
More slides like this


Slide #6.

Question 1 • I => ID => IDD => IDDD => DDDD => 1DDD => 12DD => 123D => 1234 6-9-15 6
More slides like this


Slide #7.

Quiz revu cont. 6-9-15 7
More slides like this


Slide #8.

scoping 6-9-15 8
More slides like this


Slide #9.

Quiz revu 6-9-15 9
More slides like this


Slide #10.

PATH variable • colon separated list • searched in order • can include relative paths like . 6-9-15 10
More slides like this


Slide #11.

Other commands and misc • • • • • • • • • • & ; ! || && cut –c -f sort –n –r grep –v –I $RANDOM $$ read fc tr dif ls -l 6-9-15 11
More slides like this


Slide #12.

Grep examples • • • • • • • grep "^am" /etc/passwd grep "^[abc]" /etc/passwd | more grep "^[a-c]" /etc/passwd | more grep "nologin$" /etc/passwd grep "^a.*nologin$" /etc/passwd grep "^a.a.*nologin$" /etc/passwd grep -v "^a.a.*nologin$" /etc/passwd 6-9-15 12
More slides like this


Slide #13.

Cut examples • • • • • • 6-9-15 cut -c 10-20 /etc/passwd cut -c -10 /etc/passwd cut -c 30- /etc/passwd cut -d ":" -f 5 /etc/passwd cut -d ":" -f 2,5 /etc/passwd cut -d ":" -f 3-5 /etc/passwd 13
More slides like this


Slide #14.

problem 1, due this week Write a Bash script, count.sh, which builds a table of counts for the commands under /bin which start with each letter. For example, if there are 3 commands starting with "a" (alsaumute, arch & awk) while there may be 2 commands starting with "z" (zcat & zsh). The first and last lines your script will print would be: a 3 ... ... ... z 2 Hint: use loop and array to design and implement this script. 6-9-15 14
More slides like this


Slide #15.

Homework 1 revu ls /bin > /tmp/x letters=(a b c d e f g h i j k l m n o p q r s t u v w x y z) for i in ${letters[*]} do x=0 echo -n "$i " grep "^${i}" /tmp/x | while read file do let x=x+1 echo $x > count done cat count done 6-9-15 15
More slides like this


Slide #16.

Problem 2 Write a Bash script, reverse.sh, which reverses the contents of a directory passed as a parameter. For example, assuming /my/dir contains cache cron games lib log run tmp, your program "reverse.sh /my/dir" will return "tmp run log lib games cron cache." Hint: use an array and two functions: main() and reverse(). Do not use the built-in command sort -r. 6-9-15 16
More slides like this


Slide #17.

problem 3 Write a Bash script, filter.sh, which prints those files/directories that have the size greater than the average file size of the directory passed as its first argument . Suppose for example that the directory /my/dir has five files/directories with size in parentheses : a (100) b (10) c (100) d (100) e (20), your program "filter.sh /my/dir" will list "a c d" since the size of each of these 3 files is greater than the average file size of 66. Hint: you can use 3 functions to do this: main, average, and filter, where main calls average and filter, and average computes the average file size of a directory and filter filters out those that have less than the average. 6-9-15 17
More slides like this


Slide #18.

problem 4 • Write a Bash script, insert-sort.sh, which sorts a list of command line parameters in ascending order. For example, your command will look something like: $ insert-sort.sh 7 2 3 9 -1 and type enter. Your program will return: -1 2 3 7 9 • Use only basic commands and array. Do not use any built-in commands that sort array. 6-9-15 18
More slides like this