Question

In: Computer Science

Please write a shell script called "myfilechecking" to determine whether a file belongs to one of...

Please write a shell script called "myfilechecking" to determine whether a file belongs to one of the following categories:

  • A directory;
  • A scrip file (readable and executable);
  • An executable file (not readable but executable, such as a.out);
  • A regular ascii file (only readable, such as a C source code file);
  • The file cannot be recognized.

  • Your script should display the corresponding information based on the category of the file;
  • The file name should be provided along with your script invocation, such as "./myfilechecking a.out" will display "a.out is an executable file."
  • If the file name is not provided by users, your script should indicate the problem and then terminate its execution.

  • Please test your script on our server to make sure it works properly and displays the information as required;

  • Please include the screenshot of your script along with the screenshot of the execution of your script below:

The screenshot of the script:

The screenshot of the execution of the script:

can you please paste the script code? Thank you

Solutions

Expert Solution

Note : As mentioned in question when we use script with a.out it should give output as "a.out is an executable file." But It will show "a.out is a script file" because in linux system it is showing as readable also as shown below

[vishalh@param-demo openmp-codes]$ ls -al a.out
-rwxrwxr-x 1 vishalh vishalh 8448 Oct 16 22:49 a.out

#!/bin/sh

if [  ! -e $1  ]; then
   echo "$1 does not exits."
else
    if [ -d $1 ]; then
     echo "$1 is a directory."
    fi

    if [ -r $1 -a -x $1 -a ! -d $1  ]; then
      echo "$1 is a script file."
    fi

    if [ ! -r $1 -a -x $1 -a ! -d $1   ]; then
     echo "$1 is a executable file."
    fi
    if [ -r $1 -a ! -d $1  -a ! -x $1  ]; then
      echo "$1 is a reular ascii file."
    fi
fi



Related Solutions

Write a bash shell script that takes exactly one argument, a file name. If the number...
Write a bash shell script that takes exactly one argument, a file name. If the number of arguments is more or less than one, print a usage message. If the argument is not a file name, print another message. For the given file, print on the screen its content.
Write a shell script (to run on the Bourne shell) called cp2.sh to copy all the...
Write a shell script (to run on the Bourne shell) called cp2.sh to copy all the files from two named directories into a new third directory. Timestamps must be preserved while copying files from one directory into another. Task Requirements Three directory names must be supplied as arguments to your script when it is executed by the user. In the beginning of your script you need to check that the first two directory names provided (e.g. dir1 and dir2) exist...
Write a brief shell script that will take in a specific file name, prompt the user...
Write a brief shell script that will take in a specific file name, prompt the user whether they would like to gzip, bzip2, or xz compress the file. Depending on response, the script then ought to compress the provided file with the corresponding method
Create shell scripts, .sh file. Please include a shebang line at the top of the script...
Create shell scripts, .sh file. Please include a shebang line at the top of the script as well as appropriate comments through out. Write a script that plays a simple “guess the number” game with the user. It should select a random integer in the range [0 - 10], ask the user to guess the value, and provide feedback of the form “too high”, “too low”, or “congratulations” as appropriate. After the correct value is guessed, the script should terminate.
this lab, you will write a shell script, called compare_cols.sh. This program should Read a CSV...
this lab, you will write a shell script, called compare_cols.sh. This program should Read a CSV file from standard input (STDIN). Note that in general, CSV files may contain quoted fields with embedded newlines. But for this assignment you can assume that there are no fields with embedded newlines, and therefore each new line represents a new row of the CSV file. Print a single number (integer) to standard output (STDOUT): the count of the lines in the CSV file...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell...
(10pts) Write a shell script to display your name to the screen. (10pts) Write a shell script to take a directory as an argument and display the contents of that directory (10pts) Write a shell script that takes any command as a parameter and displays help on that command (e.g. the result of the execution of man <command>). (10pts) Write a shell script that requires two file names as parameters and copies content of one file into another without asking...
Write a complete shell script that first asks the user to enter a URL. The script...
Write a complete shell script that first asks the user to enter a URL. The script should read the URL into a variable named url. The shell script should then retrieve the file associated with the URL by using the curl command. The output of the curl command should be redirected to a file named html_file. The shell script should then use the grep command to search the file named html_file for the word manhattan. Finally, the shell script should...
Create a shell script called (Main.sh). The script must call the following scripts (FileS.sh), (Work.sh), (Ether.sh),...
Create a shell script called (Main.sh). The script must call the following scripts (FileS.sh), (Work.sh), (Ether.sh), (Arch.sh) and (Buzz.sh). The first script Main.sh must have two subroutines. The First Subroutine will display the following messages on the screen: 1-Display User login name, date and time. 2-Display System boot time. 3-Working path and Shell type 4-Display Home directory and number of files and directories in your Home. 5-Message describing briefly the requited tasks.
Using Python create a script called create_notes_drs.py. In the file, define and call a function called...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called CyberSecurity-Notes in the current working directory Within the CyberSecurity-Notes directory, creates 24 sub-directories (sub-folders), called Week 1, Week 2, Week 3, and so on until up through Week 24 Within each week directory, create 3 sub-directories, called Day 1, Day 2, and Day 3 Bonus Challenge: Add a conditional statement to abort the script if...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all...
this is bash scripting. a. Write a shell script that adds an extension “.deb” to all the files in a directory. b. Write a command sequence or a script to insert a line “GHIJKLM” at every 10th line of a file? c. Write a bash command or script to find all the files modified in less than 5 days and print the record count of each.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT