Linux Homework 1

9/21/2020 CS288 Intensive Programming Homework

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

https://web.njit.edu/~mss87/cs288/hw1.html 1/1

CS288 Intensive Programming Homework 1

Homework 1 on Writing Bash scripts

The questions in this homework can be done in a couple of commands but you should do away with complex
and sophisticated commands. You need to learn how add before jumping to learning to multiply, let alone
derivatives/integrals. I’ll show how to use fancy commands when you are most familiar with basic
commands. Again, try to learn as many basic commands so that you can decide what commans to use for
variety of problems you will face in your computing career for years to come.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

1. Write a Bash script, count.sh, which builds a table of counters for the commands under /bin in
alphabetical order. For example, there are 9 commands starting with “a” (a2p addftinfo addr2line
apropos ar arch as ash awk) while there are 11 commands starting with “z” (zcat zcmp zdiff zegrep
zfgrep zforce zgrep zless zmore znew zsoelim). Exclude commands starting with non-alphabets such
as “[.” Your script will print

a 9



z 11

The above list is a sample, just one example. You Linux distro can give you a totally different number
of commands.

Use loop and array to design and implement this script.

2. Write a Bash script, reverse.sh, which reverses the contents of a directory passed as a parameter.
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.” Use an array and two functions: main() and reverse(). You
will manually manipulate the list as we did today. DO NOT use the built-in command sort -r.

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. 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 the three files/directories “a c d” is greater
than the average file size of 66. Use three functions: 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.
Use ls -l to get file size in bytes. Directories will be 4 KB, a page (be it diskblock or internal memory).
Files will come in various size. Try not to use wc or du. Use of these defeats the purpose of learning
various basic linux commands.

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.

Calculate your order
Pages (275 words)
Standard price: $0.00
Client Reviews
4.9
Sitejabber
4.6
Trustpilot
4.8
Our Guarantees
100% Confidentiality
Information about customers is confidential and never disclosed to third parties.
Original Writing
We complete all papers from scratch. You can get a plagiarism report.
Timely Delivery
No missed deadlines – 97% of assignments are completed in time.
Money Back
If you're confident that a writer didn't follow your order details, ask for a refund.

Calculate the price of your order

You will get a personal manager and a discount.
We'll send you the first draft for approval by at
Total price:
$0.00
Power up Your Academic Success with the
Team of Professionals. We’ve Got Your Back.
Power up Your Study Success with Experts We’ve Got Your Back.

Order your essay today and save 30% with the discount code ESSAYHELP