Write a shell script that takes a name of a directory, and delete all sub directories of size 0
Added by Allison S.
Close
Step 1
First, we need to take the name of the directory as input from the user. We can use the read command to achieve this. ```shell read -p "Enter the directory name: " directory ``` Show more…
Show all steps
Your feedback will help us improve your experience
Nicole Smina and 51 other AP CS educators are ready to help you.
Ask a new question
Labs
Want to see this concept in action?
Explore this concept interactively to see how it behaves as you change inputs.
Key Concepts
Recommended Videos
Write a Bash script, filter.sh, which prints those files/directories that have a size greater than the average file size of the directory. Suppose, for example, that the directory /my/dir has five files/directories with sizes 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 the file size in bytes. Directories will be 4 KB, a page (be it disk block or internal memory). Files will come in various sizes. Try not to use "wc" or "du". The use of these defeats the purpose of learning various basic Linux commands.
Akash M.
Create a shell program which: 1. Called mynewshellscript.sh 2. Displays to the terminal the message "About to begin the program" 3. Displays the current working directory. 4. Displays the current user. 5. Creates an empty file called text.txt 6. Does the following 20 times: a. Tests if the file text.txt exists b. If the file exists i. Display the message "Going to delete the file text.txt" ii. Deletes the file text.txt c. If the file does not exist i. Display the message "Going to create the file text.txt" ii. Creates a file text.txt which is the output of the list command from the current directory 7. Displays the message "Ending the program"
Supreeta N.
John I.
Recommended Textbooks
Computer Science and Information Technology
Introduction to Programming Using Python
Computer Science - An Overview
Watch the video solution with this free unlock.
EMAIL
PASSWORD