Write a script named listEmptyDir.sh that will do the following: (a) take a name of a directory as a parameter; (b) loop through all files in this directory and display their names; (c) if a file is a directory and has no files in it (empty directory), add the name of this empty directory to the file EmptyDir.txt in your current directory. If the number of parameters is not 1 or a parameter is not a directory, display the “usage” message and exit with non-zero status. Your script should demonstrate that you have investigated all possible situations.
Please don't just copy the one that already exist it doesn't explain the process well
usage() {
echo "usage: " $0 " requires an existing path to a directory or a directory in the relative path"
echo "[-h|--help] : display this message"
}
checkDir() {
directory=$1
notEmpty=false
# if anything exists in the current directory
if [[ "$(ls -A $directory)" ]]; then
echo Files in subdirectors of $1
# for every sub file or directory in the current direcotry
for sub in $directory/*; do
# if the current path is a file then output the name
if [[ -f $sub ]]; then
echo $sub
# mark the file as not empty
notEmpty=true
# else call the checkDir function again
else
checkDir $sub
# if the current path is empty put it at the bottom of empty dir
if [[ "$notEmpty"=false ]]; then
echo $sub >> EmptyDir.txt
fi
fi
done
fi
}
directory=$1
if [[ "$#" != '1' ]] || [[ "$directory" = "-h" ]] || { ! [[ -p "$directory" ]] && ! [[ -d "$directory" ]]; }; then
usage
exit 1
fi
# null out EmptyDir
truncate -s 0 EmptyDir.txt
checkDir $directory
# showing contents of EmptyDirs
echo Empty Subdirectors of $1
cat EmptyDir.txt
Write a script named listEmptyDir.sh that will do the following: (a) take a name of a...
Hello, please help with the following, you're tasked with writing a shell script named “rpsm.sh”. The script reports and prints (to stdout) selected storage management information. Think of it as “RePort Storage Management”. The easy way to describe what the script needs to do is to look at what it should display in the case where you provide incorrect parameters, or in the case where you provide “-h” for help: Usage: ./rpsm.sh <options>< directory> Reports selected information about specified directory...
For Python
| Instructions Write a script named difpy. This script should prompt the user for the names of two text files and compare the contents of the two files to see if they are the same. 1. If they are the script should simply output "Yes". 2. If they are not the script should output "No", followed by the first lines of each file that differ from each other The input loop should read and compare lines from each...
write the bash script Write a script compress_large_files.sh. This script accepts one or more command line arguments. The first argument has to be an integer; let’s call it size. If this is the only command line argument, compress_large_files.sh inspects all files in the current working directory and compresses every file of size at least size. If there is more than one command line argument, all arguments except the first one must be valid directories. In this case, compress_large_files.sh inspects the...
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...
SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5 input arguments in a for loop, but only add the even i values to sum and display the result. Problem 6: Write a shell script that accepts path of the directory and returns a count of all the files within the specified directory. (Hint: use alias to perform cd operation) Problem 7: Write a shell script that takes an ‘count’ value as an input...
using lubuntu
ce the following activities on your Linux virtual machine. Then complete estions. Write a script file which when executed will perform the following: First display today's date in dd.mm.YYYY format (e.g. 20.04.2019). Ask user to enter a name to create a directory. Create a directory by the given directory name above. . . Ask user to enter a name to create a file. Copy the file /etc/passwd to the given filename above inside the newly created directory Copy...
Part 1: Create a shell script that returns a full name associated with a userid specified in the command line argument. • Use the names found in /acct/common/CSCE215-Spring19. • Your shell script should be named “findName.sh” – Example usage: $ ./findName.sh seiei SETSUNA F SEIEI $ – Your shell script must either: Return the full name associated with the userid or Return an error message if the command line arguments are not equal to 1. or Return the message “Sorry...
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...
Write a bash shell script, deleteFilesWithZeroLength.sh, that removes all zero length ordinary files in the directory passed as an optional argument. If you do not specify the directory argument, the script uses the present working directory as the default argument. Do appropriate exception handling in your script such as:If the arguments are more than 1, print out “Too many arguments passed”.If the argument passed is a regular file, print out “XXX is regular file”.1c. If the directory doesn’t exist, print out “Directory...
Programming Exercise 4.9
Write a script named numberlines.py. This script
creates a program listing from a source program.
This script should:
Prompt the user for the names of two files.
The input filename could be the name of the script itself, but
be careful to use a different output filename!
The script copies the lines of text from the input file to the
output file, numbering each line as it goes.
The line numbers should be right-justified in 4 columns,...