Grading Rubric for CS 2505 Fall 2019 Linux02 Basic Commands ------------------------------------------------------------------------------- For questions 1-5, assume there is a directory on my CentOS virtual machine, submissions, that contains files as shown in the long listing (ls -l) below: #1013 wmcquain@centosVM submissions> ls -l total 1100 -rw-rw----. 1 wmcquain wmcquain 960 Feb 23 10:17 aaron03.prog01.1.c -rw-rw----. 1 wmcquain wmcquain 2406 Feb 23 10:17 abdel98.prog01.1.c -rw-rw----. 1 wmcquain wmcquain 2027 Feb 23 10:17 ajay99.prog01.1.c -rw-rw----. 1 wmcquain wmcquain 1468 Feb 23 10:17 ajd29.prog01.1.c -rw-rw----. 1 wmcquain wmcquain 1654 Feb 23 10:17 ajorq21.prog01.1.c -rw-rw----. 1 wmcquain wmcquain 1462 Feb 23 10:17 alexf98.prog01.1.c -rw-rw----. 1 wmcquain wmcquain 1419 Feb 23 10:17 alexfrigault.prog01.1.c -rw-rw----. 1 wmcquain wmcquain 1535 Feb 23 10:17 alexmill.prog01.2.c -rw-rw----. 1 wmcquain wmcquain 2060 Feb 23 10:17 aliadams.prog01.1.c -rw-rw----. 1 wmcquain wmcquain 2088 Feb 23 10:17 aligy.prog01.1.c -rw-rw----. 1 wmcquain wmcquain 2008 Feb 23 10:17 alyss17.prog01.2.c -rw-rw----. 1 wmcquain wmcquain 1102 Feb 23 10:17 amandal5.prog01.1.c . . . -rw-rw----. 1 wmcquain wmcquain 1345 Feb 23 10:17 zankvon.prog01.1.c -rw-rw----. 1 wmcquain wmcquain 1379 Feb 23 10:17 zhangtr.prog01.1.c -rw-rw----. 1 wmcquain wmcquain 1917 Feb 23 10:17 zhewei6.prog01.2.c -rw-rw----. 1 wmcquain wmcquain 1458 Feb 23 10:17 zicong7.prog01.1.c -rw-rw----. 1 wmcquain wmcquain 2145 Feb 23 10:17 zoromskik.prog01.1.c -rw-rw----. 1 wmcquain wmcquain 2434 Feb 23 10:17 zruijie8.prog01.1.c The directory contains over 1000 files, and you do not know all the file names. You do know that all of the file names take the following form PID.prog01.X.c where PID indicates the student who submitted the file, and X is a single digit, called the submission number. You may benefit from consulting the man page for the ls command. 1. [24 points] Assume that my current working directory is submissions. Write a single Linux command that I could execute to display the names of the files described. >>> Each part is worth 8 points. a) All and only the files, if any, for which the PID field contains the letter 'm'. ANSWER: I need to check for an occurrence of 'm' somewhere before the first '.' in the file name, and I must not restrict the value of the submission number. ls *m*.prog01.*.c // doesn't restrict the submisson number to be // a single digit ls *m*.* // doesn't restrict anything after the first '.' ls *m* // the file name format guarantees we can't have // an 'm' after the PID field ls *m*.prog01.?.c // restricts the submission number to be a single // character, but not necessarily a digit ls *m*.prog01.[0-9].c // forces the submission number to be a character // between '0' and '9' As long as the file names all follow the given pattern, any of the answers above will do. The last two depend on knowledge of regular expressions that has not been covered (yet). >>> Full credit for any of the above answers. >>> 4/8 if the answer correctly restricts the PID to have an 'm' but >>> fails for some other reason b) All and only the files, if any, for which the PID field ends with the letter 'm'. ANSWER: I need to check for an occurrence of 'm' immediately before the first '.' in the file name, and I know there can't be an 'm' except in the PID field. ls *m.prog01.*.c // doesn't restrict the submisson number to be // a single digit ls *m.* // doesn't restrict anything after the first '.' ls *m.prog01.?.c // restricts the submission number to be a single // character, but not necessarily a digit ls *m.prog01.[0-9].c // forces the submission number to be a character // between '0' and '9' As long as the file names all follow the given pattern, any of the answers above will do. The last two depend on knowledge of regular expressions that has not been covered (yet). >>> Full credit for any of the above answers. >>> 4/8 if the answer correctly restricts the PID to end with a 'g' but >>> fails for some other reason c) All and only the files, if any, for which the submission number is 2. ANSWER: I need allow any PID, but I must take into account that a PID might include the digit '2', but on the other hand, the second field cannot include a '2'. Here are some valid answers: ls *.prog01.2.c ls *.*.2.* ls *.*2* ls *.*.2* >>> Full credit for any of the above answers. >>> I'm sure there are lots of others as well, so watch for them. >>> Give up to 4/8 for partially-valid answers. 2. [16 points] Suppose my current working directory is submissions. For each part, give a single valid Linux command that I could use to create the specified tar archive. >>> Each part is worth 8 points. a) Bundle all the files in the current working directory whose names have a PID field beginning with the letter 'r' into a flat tar file named r_files.tar, so that the tar file is created in my home directory. ANSWER: I need the switches "cf" because I need to create a tar file. I need to only take files whose PID field begins with 'r'; that's equivalent to saying the file name begins with an 'r', we don't need to worry about the 'r' in the second field of the file names. Finally, I need to put the tar file into my home directory, but I do not know where the current working directory is in relation to that, so I need to specify my home directory with '~' (or perhaps /home/wmcquain): tar cf ~/r_files.tar r* >>> 2 points for cf >>> 4 points for specifying the file name mask correctly; note that >>> there are valid alternatives (e.g., using cvf, r*.* and others) >>> 2 points for specifying the destination correctly >>> Give no more than 4/8 if they get the order of the tar parameters >>> wrong. b) Bundle all the files with submission number 3 into a flat tar file named third_subs.tar, so that the tar file is in the parent of the current working directory. ANSWER: I need to restrict the submission number of the selected files, similarly to 1c. I need to put the new tar file in the parent directory. tar cf ../third_subs.tar *.*.3.c >>> 2 points for cf >>> 4 points for specifying the file name mask correctly; note that >>> there are valid alternatives (e.g., using cvf, *.*3* and others) >>> 2 points for specifying the destination correctly >>> Give no more than 4/8 if they get the order of the tar parameters >>> wrong. 3. [12 points] Repeat question 2b, but this time, create a zip archive instead of a tar file. ANSWER: The zip command takes the name of the zip file first, then the names of the files to be zip'd: zip ../third_subs.zip *.*.3.c >>> 4 points for putting the destination as the first parameter >>> 4 points for specifying the destination correctly (aside from the >>> order of the parameters) >>> 4 points for specifying the file name mask correctly; note that >>> there are valid alternatives (e.g., *.*3* and others) 4. [16 points] Now, suppose that my current working directory is the parent directory for the directory submissions. Suppose that I want to list the names of all the files in the submissions directory for which the PID field contains the character 'g'. >>> Each part is worth 8 points. a) Why might the following command not produce the output I want? A good explanation would include an example of a file name that would be shown even though it doesn't have a 'g' in the PID field. ls --format=single-column ./submissions/*g* ANSWER: This will include every file, because every file name contains a 'g': aaron03.prog01.1.c The pattern *g* doesn't require the 'g' to come somewhere before a '.'. >>> 6 points for saying this doesn't require 'g' to precede a '.'. >>> 2 points for an example (which is trivial) b) Why might the following command not produce the output I want? A good explanation would include an example of a file name that would be shown even though it doesn't have a 'g' in the PID field. ls --format=single-column ./submissions/*g*.* ANSWER: This only says there must be a '.' somewhere after a 'g', and that's true of all the file names. This doesn't say the 'g' must precede the first '.': aaron03.prog01.1.c. >>> 6 points for saying this doesn't require 'g' to precede the first '.' >>> 2 points for an example (which is trivial) For question 5, suppose you current working directory is J3Files, which has the following contents, including a directory tree rooted in CS3114: J3Files |-- CS3114 | `-- J3 | |-- Client | | `-- Point.java | `-- DS | |-- Compare2D.java | |-- Direction.java | |-- Lewis.class | `-- prQuadTree.java |-- gradeJ3.sh |-- LogComparator.jar |-- PRGenerator.jar `-- testDriver.java 5. [32 points] For each part, write a single Linux command that will achieve the specified action, with no unnecessary side-effects, assuming the command will be executed in the directory J3Files. The parts are independent; in other words, each will be performed with the system in the state shown above. You will find a number of man pages to be very useful. There will be no partial credit for these answers. >>> Each part is worth 8 points. a) Copy the file testDriver.java to the user's ~/temp directory. ANSWER: cp testDriver.java ~/temp >>> All or nothing for this one. b) List the files in the subdirectory DS, sorted in ascending order by file size (smallest files first). ANSWER: ls -rS CS3114/J3/DS/ >>> 2 points for 'r' >>> 2 points for 'S' (case-sensitive, -s is different) >>> 4 points for correctly specifying the directory c) Copy the entire directory tree rooted in CS3114, including all the files therein, to the user's ~/backup directory. ANSWER: cp -r CS3114 ~/backup >>> 4 points for '-f' >>> 2 points for specifying the directory to be copied >>> 2 points for specifying the destination d) Remove the entire directory tree rooted in J3, including the directory J3 itself. ANSWER: rm -rf CS3114/J3 >>> 3 points for 'r' >>> 3 points for 'f' >>> 2 points for specifying the target directory