Tutorial Week 3
  • Write a command ``dir'' to perform a long listing of files in the current directory. Shell script file contains ls -l
  • Write a pipeline to count the number of files in the current directory. ls | wc -l
  • Write a shell script that uses a pipeline to count the total number of bytes in all files in the current directory. cat * | wc -c
  • Write a pipeline which, given a pattern and a filename, will write to standard output the first line (and only the first line) of the file containing the pattern. grep $1 $2 | head -1
  • Write a shell script that takes two arguments to show the differences in file names between two directories. ls $1 > /tmp/tmp1$$ ls $2 > /tmp/tmp2$$ diff /tmp/tmp1$$ /tmp/tmp2$$ rm -f /tmp/tmp*
  • Write a shell script that given a pattern will search all files recursively from the current directory and report the names of all files containing the pattern. find . -name '*' -exec grep -l $1 {} \;
  • Write a shell script to change a filename given as argument to lower case, and rename the old file name to the new file name. new=`echo $1 | tr "A-Z" "a-z"` mv $1 $new Laboratory Week 3
  • Create shell commands for each of the questions of the week 3 tutorial. Test each of them by running the command testit Question-number filename where Question-number is one of 3.1, 3.2, etc and the filename is the name of the file containing your shell script.