Question

In: Computer Science

Revision Question 1 on Linux. Please briefly explain the shell script given. a) You have just...

Revision Question 1 on Linux. Please briefly explain the shell script given.

a) You have just logged in and have a directory called "images" in your home directory containing the following files:

favicons login.png logo.png newlogo.png

where "favicons is a directory and contains the files

favicon.ico favicon.gif favicon.png favicon.jpg

Describe the results you would expect when executing the following shell commands:

i) ls images/*og* | wc -1

ii) ls -ld images/*

iii) rmdir images/favicons

iv) cp images/*/*png images

v) rm -r images

(assume each command is run when the directory "images" is as described above)

b) Consider the following short shell script:

#!/bin/sh

mkdir $3

for i in $1/*$2

do

cp $i $3

touch $i

done

If this script is stored in a file called script1, what would be the effect of running this shell command:

./script1 images png newdir

c) Describe the underlying principle behind the Linux command set - often called the "UNIX philosophy".

  

  

Solutions

Expert Solution

a) Let me start by explaining the commands given in the script.

ls - list directory contents

wc - word count. -l is used to count lines

rmdir - deletes an empty directory

cp - used to make a copy

rm - remove command. -r is used to do a recursive remove.

OUTPUT

  1. 3

The count includes login.png, logo.png, newlogo.png

2. Displays the list of files in images directory with details

3. "Cannot delete non-empty folder"

4. Copies all the png images from favicons folder to images folder. Though, doesn't generate any output

5. Deletes the entire folder images alongwith it's subdirectories and files. No output is produced.

b)

This bash script is run with certain arguments. The arguments are referred with $1, $2 and $3 respectively.

Suppose the bash script is run as "./script1 images png newdir"

Then the script does the following:

  1. Creates a directory called "newdir"
  2. Iterates over all files/directories whose names end with "png" and which reside in a folder named "images".
    1. Copies these files to the new folder "newdir"
    2. Updates the last accessed timestamps of the original files.

Related Solutions

Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given...
Design two shell programs working on Linux (Ubuntu) Design a shell script program, 1) reading given only two integer numbers from command line arguments and computing their multiplication. If two integer numbers are not given, print “Wrong Input” on your screen. Note that, the number of arguments is known when the script runs. Take a screenshot showing your shell program and its execution step. Design a shell program to remove all the shell programming files ending with sh on your...
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string...
Linux Script Convert String (Part 1) Write a simple shell script that takes a permission string expressed as -rwxrwxrwx and prints out whether or not theobject is a directory, file or link. The string is read in from standard input. Convert String (Part 2) Modify the script so its able to print out the octal permission which the string represents along with the file type. This is in addition to part 1. Convert String (Part 3) For the script in...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt...
LINUX In Linux command line write a shell script ex1.sh that uses IF THEN to Prompt the user to "Enter a number between 1 and 10". (Hint: Use the 'echo' and 'read' commands in the script. See the slide about the 'read' command) If the number is less than 5, print "The number is less than 5" (Hint: You will read input into a variable; e.g. read NUM. In the IF statement, enclose $NUM in quotes; e.g. "$NUM". Also, remember...
Perl is a programming language that can be used on Linux. Write a Perl shell script...
Perl is a programming language that can be used on Linux. Write a Perl shell script named phone.pl that prompts the user to enter first or last or any portion of person’s name, so that can be found the appropriate entry in the phone directory file called “phones”. If the user tries to enter name as the argument on the command line, he/she will get a warning message “You need to provide name when prompted by this script!” If the...
Linux Sign into your lab account Write a bash shell script that does the following: Print...
Linux Sign into your lab account Write a bash shell script that does the following: Print out a friendly welcome message Ask the user for the name of their favorite animal Grep that animal from a text file noises.txt Tell the user what that animal says (i.e. what noise does it make) If the animal does not exist ask the user what noise the animal makes Store that new information in noises.txt
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within...
Part 2 – Scripting Goals:  Write a bash script  Use linux shell commands within your script  Provide user feedback  Use loops  Use conditionals Remember to use chmod +x to make your file executable! Each script is 5 points in the Specifications portion of the rubric. Don’t forget to maintain good standards and comments. Script 1 – Echo-back some information Write a script name hello.sh that will take the user’s first name as a command line...
Linux Shell Prpgramming 1.Write a quiz-script which will provide some statistics about a quiz results (summarize...
Linux Shell Prpgramming 1.Write a quiz-script which will provide some statistics about a quiz results (summarize how many good answers and how many wrong answers were provided). The script should use up to 3 execution parameters. When executed with two parameters (let’s call it interactive mode), it should assume, that the first file contains a list of questions and the second file contains correct answers to these questions. In such execution case your script should display questions one by one...
Linux Given a passed parameter to a script, request a number from the user and print...
Linux Given a passed parameter to a script, request a number from the user and print the parameter as many times as that number.
Explain what each of the following metacharacters mean within the shell linux. 1. > (greater than)...
Explain what each of the following metacharacters mean within the shell linux. 1. > (greater than) 2. < (less than) 3. | (vertical bar)
Please write shell scripts in Kali Linux to complete the following tasks. Task A - Take...
Please write shell scripts in Kali Linux to complete the following tasks. Task A - Take your UIN Write a script like below that reads and displays the MIDAS ID if the following requirements are satisfied: Only lower case letter [a-z] and numeric character[0-9] are allowed MIDAS ID must between 4 to 8 digits Test your script with the following examples: Your MIDAS ID in lower case Your MIDAS ID w.one upper case A string less than 4 digits A...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT