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

MANAGING FILES/DIRECTORIES Problem 8 (18 points): Answer the following questions

ID: 3588845 • Letter: M

Question

MANAGING FILES/DIRECTORIES Problem 8 (18 points): Answer the following questions regarding managing files and directories a) What command would delete the directory lopt/uselessFiles including all of the files and subdirectories within it? 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? 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): e) Change to the directory /opt/games/ f) Create a new directory called "pacman" inside of this directory g) While still inside of /opt/games, create a new file called "highscores" inside of the pacman directory (use a relative path/file name instead of an absolute path/file name) h) While still inside of /opt/games, rename the "highscores" file inside of the pacmar directory to "scores" (use an absolute path/file name instead of a relative path/file name for both source and destination filenames) i) Change to the directory "pacman" j) Set the permissions of the "scores" file (using numeric notation) to be -rw-r--r-- k) Make a copy of the "scores" file in this same directory called "scores.backup" I) Change to the parent directory /opt/games/ using '..' notation m) Inside of this directory, remove the empty directory “tetris" (assume it exists) n) Delete all of the files inside of the "pacman" directory, including the "pacman" directory itself

Explanation / Answer

a. rm -rf /opt/uselessFiles/* //this will delete all the files and subdirectories within "opt/uselessFiles/" directory

b. cp -i sourcefile destfile //this will prompt before overwriting if destfile already exist.

c. mv old-name new-name //this will rename the file or directory with name "old-name" to "new-name"

d. rmdir directory-name //The rmdir command remove the DIRECTORY "directory-name", if it is empty. If a directory is not empty you will get an error: rmdir: directory-name: Directory not empty

e. cd /opt/games/ // this will change the directory to /opt/games/

f. mkdir pacman //create directory pacman inside current directory

g. touch pacman/highscores //create empty file highscores within pacman directory. Since we have not used "/" before pacman, it indicate relative path to my present working directory

h. mv /opt/games/pacman/highscores /opt/games/pacman/scores //Both source and destination have absolute path

i. cd pacman // change the directory to pacman

j. chmod 644 scores //change the permission to -rw-r--r-- , where 644 is the corresponding decimal code of the permission 110100100 in binary.

k. cp scores scores.backup //copy of "scores" file to "scores.backup"

l. cd ../ //this will change to parent directory /opt/games , ../ is relative path of parent directory

m. rmdir tetris //this will remove empty directory tetris

n. rm -rf pacman // this will delete all the files inside pacman including pacman directory itself