Question

Write a bash script that prompts a user with a menu of choices: Get the total...

Write a bash script that prompts a user with a menu of choices:

  1. Get the total number of shell files from the current directory

  2. Get the total size of all the shell files from the current directory

  3. Get the total number of empty files in the system from the current directory

Each option must be its own specific function. linux only

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

Get the total number of shell files from the current directory.
find -name '*.sh' -print | wc -l

Get the total size of all the shell files from the current directory
find -type f -name '*.sh' -exec du -ch {} + | grep total$

Get the total number of empty files in the system from the current directory

find -size 0 | wc -l

Here is a bash script that prmotps user with a menu a given choices.

!/bin/bash

options=("1- Get the total number of shell files from the current directory" "2- Get the total size of all the shell files from the current directory" "3- Get the total number of empty files in the system from the current directory")
select num in "${options[@]}"
do
        case $num in
                "1- Get the total number of shell files from the current directory")Here is
                        find -name '*.sh' -print | wc -l
                        ;;
                "2- Get the total size of all the shell files from the current directory")
                        find -type f -name '*.sh' -exec du -ch {} + | grep total$
                        ;;
                "3- Get the total number of empty files in the system from the current directory")
                        find -size 0 | wc -l
                        ;;
        esac
done

Here is the menu file/bash script:

root@kali: -/Desktop File Edit View Search Terminal Help Open A menu.sh Desktop !/bin/bash Save >> do options=(1. Get the to

Here is the output:

root@kali: - /Desktop File Edit View Search Terminal Help root@kali:-/Desktop# ./menu.sh ./menu.sh: line 1: !/bin/bash: No su

Add a comment
Know the answer?
Add Answer to:
Write a bash script that prompts a user with a menu of choices: Get the total...
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
  • I need a bash script that prompts the user for a filename within a directory, and...

    I need a bash script that prompts the user for a filename within a directory, and if the file/subdirectory exists to gzip them. Directories should be tarred and zipped, files should just be gzipped. This should poll inside of a loop to keep prompting the user until the user ends the script.

  • In Putty 1. Create Bash shell script that would let a user make a copy of...

    In Putty 1. Create Bash shell script that would let a user make a copy of all the files in a directory. (3 points) 2. Create two Bash shell scripts that will perform some work (of your choice). (2*3 = 6 points) 3. Create a Bash shell script that would serve as a menu for the three scripts you have created. (1 point)

  • Homework No.2 CSC 222 Write a shell script program called "countf.sh" that will count how many...

    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...

  • Problem 1 Write a BASH script to create a user account from the Linux system on...

    Problem 1 Write a BASH script to create a user account from the Linux system on which your script is run. The script should process two positional parameters. First positional parameter is supposed to be a string with a user name (e.g., user_name) Second positional parameter is supposed to be a string with a user password (e.g., user_password) In your script: Check if two positional parameters were passed to your script when it was invoked If NOT, print an appropriate...

  • 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...

  • UNIX Write and run a simple shell script name mymenu that creates a simple command menu....

    UNIX Write and run a simple shell script name mymenu that creates a simple command menu. The script should present menu items (see below), prompts the user for a selection, and then executes the appropriate command selected. [Submit your script and the results of a test case for a, b, c, and d selections]     COMMAND MENU a. Current date and time b. Name of the working directory c. Contents of the working directory Enter a, b, or c:

  • Write a bash script to protect a directory. Your script should notify a user of the...

    Write a bash script to protect a directory. Your script should notify a user of the following: -New file was created -Permission changes -Ownership changes -File size changes -Modification date changes Your script should have two operation modes, protect and check. Use command line flags, -p <directory> and -c <directory> to decide which mode to operate in. In protect mode, your script should create a file called .protect inside the directory you want to watch. You will use this file...

  • Write a script in matlab that prompts the user to input the day, month, and year;...

    Write a script in matlab that prompts the user to input the day, month, and year; determine the day of the year (the number of days including the current day). Be sure to take leap year into account. Use a for loop Test your code on the following dates: February 28, 2015 April 9, 1976 October 12, 1887 Create a script that performs the same function as repmat. The only built-in commands you may use are input, size, and disp.

  • Write a script using the bash shell to add new users to the system. The script...

    Write a script using the bash shell to add new users to the system. The script should read user information from a comma-delimited file (each field should be separated by a comma). The filename should be passed to the script as a command-line argument. Be sure the script contains a usage clause. The input file should contain the user information with one user per line. As the system administrator, you should determine the information necessary for each user to properly...

  • matlab The Homework should be submitted as a script (.m) file Write a script areaMenu that...

    matlab The Homework should be submitted as a script (.m) file Write a script areaMenu that will print a menu consisting of "Cylinder," "Circle," and "Rectangle." It waits for the user to choose from the menu then call the corresponding function of each choice as follows: 1- Cylinder will call the function (cyl) which prompts the user for the radius and height of the cylinder, then calculates and prints area of the cylinder. 2- Circle will call the function (cir)...

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