Question

Homework No.2 CSC 222 Write a shell script program called countf.sh that will count how many files or directories recursively. beside the file counts, also report how many files for each types (directory or regular files). It will either take arguments for specific directories and no argument. If no argument, it will read the current working directory as the starting point. Please also provide -h option to print out how to use your countf.sh program % ./countf.sh % ./countf.sh file1 file2 dir 96./countf.sh diri dir2 96./counti.sh-h hints: I would write a script function to process a count for each directory and return a number of files to be added up. You should have your linux or linux-like environment, either using virtual machine or have your own linux box

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#!/bin/bash
#countf.sh

declare -i fc="0" #fc is the file counter varialble
declare -i dc="0" #dc is the directories counter variable
for file in /*
do
if [ -f $file ] #increasing fc if file is found
then
((fc++))
elif [ -d $file ] #increasing dc if directory found
then
((dc++))
fi
done
echo The files total "$fc"
echo The directories total "$dc"
echo $?

Add a comment
Know the answer?
Add Answer to:
Homework No.2 CSC 222 Write a shell script program called "countf.sh" that will count how many...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a bash shell script to carry out each of the following tasks: What to Do:...

    Write a bash shell script to carry out each of the following tasks: What to Do: a. Safe Delete: When you use the “rm” command in Linux, it will delete the specified files, with no chance for recovering them back later. Write a script (called srm) that will safely delete the files passed to it as command-line arguments. For example, typing the command: “srm file1 file2 file3”, the script shall not actually delete these files, but instead it shall move...

  • Write a script using simple shell commands. The script takes a command line argument that specifies...

    Write a script using simple shell commands. The script takes a command line argument that specifies a directory dir. The script first changes directory to dir, then prints the following in sequence: (a) A line starting “Current date and time: ”. Then on the same line, the current time and date. (b) A line starting “Current directory is : ”. Then, on the same line, the absolute pathname of the current working directory. (c) An empty line (d) The line...

  • You are currently running/debugging a shell script program in the foreground that seems to be in an infinite loop, to terminate/kill the shell script program. 7. (type/enter - control C to send a &#3...

    You are currently running/debugging a shell script program in the foreground that seems to be in an infinite loop, to terminate/kill the shell script program. 7. (type/enter - control C to send a "program interrupt" ) or (contact the sysadmin person to kill your shell script program) 8. The UNIX/Linux exit command entered on the KORN shell command line will exit the shell session properly (best practice). [True / False] When killing a background process with the kill command you...

  • I need this done ASAP. Please write a bash shell script that does the following: Prints...

    I need this done ASAP. Please write a bash shell script that does the following: Prints out how many users are logged on. This can be accomplished using who and wc. Prints out a list of currently logged on users. This can be accomplished using who, grep, regular expressions, and echo. Prints out how many processes you have running from past days, and a list of those jobs. Use `whoami` to get your username. Run ps -ef and see how...

  • Objective : Write a C Shell script which copies all files(*.java and *.class) from your home dire...

    Objective : Write a C Shell script which copies all files(*.java and *.class) from your home directory to a new one, and Analyze the new directory information such as number of files, user permissions, and disk usage. Sample Output:                                                    << CS Directory Analysis >>      Date:   ============================================================ Current Directory: /home/tomss New Directory Created : /home/tomss/pgm01 File information Total Number of files : 22 files Directory files:   0 files Plain text files:   10 files File have read permissions: 3 files File have...

  • Step 3: How would you write this script in C? It needs to do the things...

    Step 3: How would you write this script in C? It needs to do the things required in step 3. 1. You have received a new batch of distinguished users; their basic information is located in newusers.tar. Inside of the tar file, there is a file called "newusers.txt" which contains a colon-separated entry for each user: the username, the uid, the GECOS information, and the user's preferred shell. Also in the tar file you will find a public key for...

  • Write a script that works in vim: We are given a Java program RandomTest.java that generates...

    Write a script that works in vim: We are given a Java program RandomTest.java that generates specified number of random integers in the range [0...99]. The program prints FAIL if either 0 or 99 is generated (along with a count of how many times). Otherwise it prints PASS. The program takes the number of random integers to generate as a command line argument as shown below. Note that the given results each time is is run. [an@localhost ~] java Random...

  • Write a python program to print a poem of your own choice. Then count how many...

    Write a python program to print a poem of your own choice. Then count how many words in each line, use a print statement to add the number of words in each line and display it. Hint: use print(3+5+4+6), for example. My poem: 'Tis better to have loved and lost Than never to have loved at all.'

  • Self-check exercise: While-loops The value of (π^2)/8 can be approximated by the series Write a script...

    Self-check exercise: While-loops The value of (π^2)/8 can be approximated by the series Write a script that evaluates this expression, ignoring all terms that are strictly smaller than .000001. Your script should display the number of terms summed and the sum. Use a while-loop. Think about the initialization of your variables and the order of computation carefully! In the loop body you need to calculate the value of a term only once. We use the above series for approximating (π^2)/8...

  • Description: Overview: You will write a program (says wordcountfreq.c) to find out the number of words and how many times each word appears (i.e., the frequency) in multiple text files. Specifically,...

    Description: Overview: You will write a program (says wordcountfreq.c) to find out the number of words and how many times each word appears (i.e., the frequency) in multiple text files. Specifically, the program will first determine the number of files to be processed. Then, the program will createmultiple threads where each thread is responsible for one file to count the number of words appeared in the file and report the number of time each word appears in a global linked-list....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT