Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cs288 Intensive Programming in Linux

Similar presentations


Presentation on theme: "Cs288 Intensive Programming in Linux"— Presentation transcript:

1 Cs288 Intensive Programming in Linux
Instructor: C F Yurkoski Section web site: 6-9-15

2 6-9-15

3 Linux access ssh to afs5.njit.edu or use putty, etc. 6-9-15

4 Quiz 1 results Not yet available 6-9-15

5 Quiz1 revu 6-9-15

6 Question 1 I => ID => IDD => IDDD => DDDD => 1DDD => 12DD => 123D => 1234 6-9-15

7 Quiz revu cont. 6-9-15

8 scoping 6-9-15

9 Quiz revu 6-9-15

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

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

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

13 Cut examples cut -c 10-20 /etc/passwd cut -c -10 /etc/passwd
cut -d ":" -f 5 /etc/passwd cut -d ":" -f 2,5 /etc/passwd cut -d ":" -f 3-5 /etc/passwd 6-9-15

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

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 let x=x+1 echo $x > count done cat count 6-9-15

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

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

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 and type enter. Your program will return: Use only basic commands and array. Do not use any built-in commands that sort array. 6-9-15


Download ppt "Cs288 Intensive Programming in Linux"

Similar presentations


Ads by Google