Question

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.

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

In case of any queries, please revert back.

=================== CODE BELOW ================

#!/bin/bash

#### Not giving any condition for infinite loop
while :
do
   #### Taking input and checking if file or directory
   echo "Enter File Name or Directory Name"
   read PASSED
   if [[ -d $PASSED ]]; then
       echo "Zipping the directory"
       tar -cvf test1.tar $PASSED
   elif [[ -f $PASSED ]]; then
       echo "gzipping the file"
       gzip $PASSED
   fi
done

============== SCREENSHOTS BELOW ===================

Activities Terminal Tue 23:07 ujjwal@shadow:-/Desktop/HomeworkLib File Edit View Search Terminal Help (base) ujjwal@shadow:~/Deskto

Add a comment
Know the answer?
Add Answer to:
I need a bash script that prompts the user for a filename within a directory, and...
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 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 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: Get the total number of shell files from the current directory Get the total size of all the shell files from the current directory Get the total number of empty files in the system from the current directory Each option must be its own specific function. linux only

  • Write a bash script to find all the files ending with .c recursively for every directory...

    Write a bash script to find all the files ending with .c recursively for every directory in your current working directory, then copy each one to a folder called programs, need handle duplicates by appending the number to the end of the file (ex main.c main-1.c ) compile them and generate a report report should look like: main.c compiles prog2.c failed main-2.c compiles etc.

  • (java) Write a While loop that prompts the user for only even numbers. Keep prompting the...

    (java) Write a While loop that prompts the user for only even numbers. Keep prompting the user to enter even numbers until the user enters an odd number. After the loop ends, print the sum of the numbers. Do not include that last odd number. You should not store the numbers in an array, just keep track of the sum. Make sure to use a break statement in your code. You may assume that a java.util.Scanner object named input has...

  • Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file...

    Finish the given ProcessFile.java program that prompts the user for a filename and reprompts if file doesn’t exist. You will process through the file skipping any text or real (double) numbers. You will print the max, min, sum, count, and average of the integers in the file. You will want to create test files that contain integers, doubles, and Strings. HINT: Use hasNextInt() method and while loop. You may also want to use Integer.MAX_VALUE and Integer.MIN_VALUE for the initialization of...

  • I'm stuck, if you can provide the code I can put it into the BASH environment...

    I'm stuck, if you can provide the code I can put it into the BASH environment Executing tasks: In this section of the project, you will demonstrate your ability to execute Linux commands to create files and create and organize the Linux directory structure. At the end of this section, you will create a log file that will include a list of all the commands you used to complete these steps. VII. In the workspace directory, create new directories titled...

  • SHELL SCRIPT: Provide the following questions with the codes and command line Problem 5: Take 5...

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

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

  • This script will create a dictionary whose keys are all the directories listed in thePATH system...

    This script will create a dictionary whose keys are all the directories listed in thePATH system variable, and whose values are the number of files in each of these directories. The script will also print each directory entry sorted by directory name. The script will use the following five functions to get the required results get_environment_variable_value() get_dirs_from_path() get_file_count() get_file_count_for_dir_list() print_sorted_dictionary() get_environment_variable_value() The header for this function must be This function must accept a shell variable as its only parameter The...

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

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