Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Working individually you are to create three scripts. These scripts will perform

ID: 3846034 • Letter: W

Question

Working individually you are to create three scripts. These scripts will perform the functions described below.

Script 1:

Perform a ls -al on the files within the user's home directory and save it to a file called ls.dat within your ~ directory

Save the tree information for the /home directory in a file called tree.dat within your ~directory

Create a new directory in your home directory called "backups"

Move the files you just created to the new directory

Rename the files that you just moved to "ls.bu" and "tree.bu".

Script 2:

Ask the user for their name

Create a file called "daily.dat" within the home directory

Ask the user for a line of text that the system should save to the file

Add to the file the line of text entered by the user

Ask the user for a second line of text that the system should save to the file

Append at the end of the file the line of text entered by the user

Create a copy of the file in the directory "backups" within the home directory, renaming the file daily.bu.

Script 3:

Ask the user for a file's name

If the file exists, ask them if they would like to (C)opy, (M)ove, or (D)elete it by choosing C, M, or D

If the user chooses C, ask for the destination directory and move it there

If the user chooses M, ask for the destination directory and move it there

If the user chooses D, delete the file.

For Script 3 ensure that the user enters only C, M, or D, warning them about the mistake if they should enter something else.

Explanation / Answer

Script 1:-

cd /home

ls -al > ls.dat

tree /home > tree.dat

mkdir backups

mv -t /home/backups ls.dat tree.dat

cd backups

mv ls.dat ls.bu

mv tree.dat tree.bu

Script 2:-

echo ' Enter your name '

read name

cd /home

>daily.dat

echo 'Enter some text'

read text

echo $text >> daily.dat

echo 'Enter second line'

read text2

echo $text2 >> daily.dat

cp daily.dat /home/backup

mv daily.dat daily.bu

Script 3:-

echo 'Enter File name'
read fname
if [ -f $fname ]
then
echo "Enter (C)opy, (M)ove, or (D)elete"
read option
   if [ $option == "C" ] || [ $option == "c" ]
   then
       echo "Enter destination"
       read destination
       cp $fname $destination
   else
   if [ $option == "M" ] || [ $option == "m" ]
   then
       echo "Enter destination"
       read destination
       mv $fname $destination
   else
   if [ $option == "D" ] || [ $option == "d" ]
   then
       rm -rf $fname
       echo "File has been deleted"
   else
       echo "You have entered wrong option please Enter (C)opy, (M)ove, or (D)elete"
   fi
   fi
   fi
else
echo "File does not exist"
fi

Please Rate!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote