In: Computer Science
QUESTION 5
1. Switch to insert mode, and then create a script that performs the following:
• Sets the environment for the script to bash
• Have at least two comment lines that state the purpose of the script
• Clear the screen
• Sends messages back to the screen informing the user of what he or she is seeing displayed on the screen
• Have the script perform the following:
o Show your home directory
o Show your current working directory
o Create a directory called demo, and send any errors to a null file so the user does not see them on the screen.
o Switch to this new directory
o Show you are in the demo directory
o Place a empty file named file1 in the demo directory, then
o Display a long list of the contents of this (demo) directory
o Change back to your home directory
o Display a long list of all the files in your home directory
2. What construct did you use to send command errors to a null file in your script?
Answer:__________________________
4 points
QUESTION 6
Save your changes and exit the vim editor.
Command(s) to save your file and exit the vim editor?
Answer:___________________________________
2. Display the permissions for your script.
What command did you use?:__________________________
Answer:________________________
3. Does the owner have execute permission?
Answer:____________________________________________
4. Give the user (owner) execute permission to run the script.
What command did you use to change the permissions on the script?
Answer:__________________________________________
What notation did you use to change permissions: symbolic or numeric (octal)?
Answer:____________________________________________
5. Run the script.
What command did you use to run the script?
Answer:____________________________________________
Please find the below answers. Please provide your feedback
Thanks and Happy learning!
QUESTION 5
1. Please see the script below in the code section
2. The construct used is : 2>/dev/null, Here the 2 indicates the standard error. So basically we are just redirecting the errors printed to standard error to /dev/null file.
QUESTION 6
1. Command to sane the file and exit the wim console is : wq
Here 'w' means write and 'q' means quit. So to exit from vim editor press 'esc' key then type colon(:) and type 'w' and then type 'q'. Then press enter key to exit the vim console.
2. Use the command ls -l to display the long listing of the file. This long listing included the permission of the file.
3. Yes the owner has the execute permission. The permissions for a file can be read(4), write(2) or execute(1) or the combination of the three. So if a file has the permission 755 then that means the owner has read+write+execute (4+2+1 = 7) permission asn others has only read+execute(4 + 1= 5) permission.
4. command to change the permission is 'chmod'.
So to give the owner the permission to execute us the command 'chmod u+x script.sh' [assuming that the shell script file name is script.sh, here 'u' means the user/owner]
One can use symbolic (ie r,w,x) or numeric (ie 4, 2, 1) notatiosn to add/remove the permissions. In the above command we user the symbolic notation.
5. The script can be run using the command ./script.sh
QUESTION 5
1.
#!/bin/bash
#Above line sets the environment for the script to bash
#Purpose of this script is to practice the
#basic unix/Linux commands
#Clear the screen
clear
#Display message in the screen
echo "Users home directory is : $HOME"
echo "Users current directory is :`pwd`"
echo "Creating directory with name demo."
mkdir demo 2>/dev/null
echo "Switching to the demo directory."
cd demo
echo "Users current directory is :`pwd`"
echo "Creating an empty file named file1 in the demo directory."
touch file1
echo "Long listing of the demo directory is:"
ls -l .
echo "Switching back to home directory"
cd $HOME
echo "Users current directory is :`pwd`"
echo "Long listing of all the files in the home directory is:"
ls -l $HOME