In: Computer Science
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".
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
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: