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

Problem 8 (18 points) Answer the following questions regarding managing files an

ID: 3849291 • Letter: P

Question

Problem 8 (18 points) Answer the following questions regarding managing files and directories. a) What does the command rm ri /no/longer/needed/ accomplish? b) What command flag can you use with cp so that it doesn't accidentally overwrite a file if it already exists (hint: look up the man page for cp)? c) Which command can be used to rename a file or directory? d) What command exists to delete a directory if and only if it is already empty e) Give the needed commands to accomplish the following scenario (use only 1 command for each one, and assume that each command affects the commands that follow it Change to the directory /store/inventory/food/ Create three new directories called "apple", potato and "kiwi" inside of this directory While still inside of /store/inventory/food/, create two new files, one called prices txt" inside of the apple" directory and another called "stock" inside of the current directory use relative path file names instead of absolute p names While still inside of store/inventory/food, move the "prices.txt'' file from inside of the apple" directory to the "kiwi" directory, while changing its name to "price.txt instead. (use absolute path file names instead of relative path/file names Change to the directory "potato" Create a new file here called "idaho' Set the permissions of the "idaho" file (using symbolic notation) so that the group and others have only execute permission Make a copy of the "idaho" file to the /store/inventory/ directory called backup" (use relative path/file names) Change to the directory store/ using notation Delete all of the files inside of the "inventory" directory, including the inventory" directory i of the files inside of your current directory to ensure the directory has List a been deleted

Explanation / Answer

a) the command rm -ri /no/longer/needed is used for removing the files from the directory
it will remove all the files in /no/longer/needed folder and the explanation of the
parameters is given below.

-i means it will give you a prompt before every removal
-r means remove directories and their contents recursively.


b) cp -n is the command that is to be used so that it does not accidentally overwrite a file if it already exists.

-n means --no-clobber
it will not overwrite the file if it already exists

Example: cp -n oldfile.txt mynewcopiedfile.txt

C) the command used to rename a file or a directory is by using mv command we can rename a file or a directory

example: mv oldname newname

usage : mv [OPTION]... [-T] SOURCE DEST
or: mv [OPTION]... SOURCE... DIRECTORY
or: mv [OPTION]... -t DIRECTORY SOURCE...
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

d) the commands exists to delete a directory if and only if it is already empty is given below.

1. rmdir is the command that is used to delete a directory if and only if it is already empty
Example : rmdir sample/testdirectory