Title: Mid-Term Exam
Course: CIS 121: Linux/UNIX I: Fundamentals ~ For IGNITE Review

Q: Write a single command to list the non-hidden files and directories in pgeyer's home directory that begin with a digit. Do not expand the directories. The command should work from anywhere on the system.
A: ls -d ~pgeyer/[0-9]* / ls -ld ~pgeyer/[0-9]* / ls -dl ~pgeyer/[0-9]*

Q: Write a single command to see how many users who are taking CIS 121 are logged in. List only information for CIS 121 logins. Remember, a CIS 121 uname does not have an "is" as part of it.
A: w | grep c121 | wc -l / finger | grep c121 | wc -l / who | grep c121 | wc -l / who | grep "c121" | wc -l

Q: Write a command to PRINT ON THE DEFAULT PRINTER the CONTENTS of all files in your home directory that start with "printme". That command should work from anywhere. Do not include your uname in the command. I want the contents of the files, not just a list of names.
A: cat ~/printme* | lp / lp ~/printme* / cat ~/printme* ~/.printme* | lp / lp $HOME/printme* / more ~/printme* | lp

Q: Write a command to display the number of users currently logged on. One number only as the output.
A: who | wc -l

Q: PRINT ON THE PRINTER called "be300" a list of non-hidden files in your current directory whose names begin with a digit. Do not list the contents of the files, just the names of the files.
A: ls -d [0-9]* | lp -d be300 / ls -ld [0-9]* | lp -d be300 / ls [0-9]* | lp -d be300 / ls ./[0-9]* | lp -d be300 / ls -ld ./[0-9]* | lp -d be300 / ls -l [0-9]* | lp -d be300

Q: List four ways to get from where ever you are to your home directory. Do not log out.
A: cd ; cd ~ ; cd ~uname ; cd <relative path> ; cd <absolute path> ; cd $HOME / cd ; cd ~ ; cd ~uname ; cd $HOME

Q: Where was Linux developed?
A: Helsinki / University of Helsinki / Finland / Helsinki, Finland / University of Helsinki, Finland / U of Helsinki / Helsinki Finland / In Helsinki, Finland / The University of Helsinki, Finland / Linux was developed in Helsinki, Finland / The University of Helsinki / University of Helsinki in Finland / Helsinki, Finland (that's not in South America) / U of Helsinki Finland

Q: Who developed Linux?
A: Linus Torvalds / Linus Benedict Torvalds

Q: When was Linux developed?
A: 1990 / 1991 / 1990/1 / 1990/91 / 1990/1991 / 1990-91 / 1990-1991 / 90/91 / 199{0,1} / about 1990 / approx 1990 / '90-'91 / 1990 91 / 1990 released in 1991
If wrong: Linux was developed in 1990 and released in 1991.

Q: Will Phil ever get tired of those questions about who, what and when for UNIX and Linux?
A: No
If wrong: Phil will never get tired of those questions about who, what and when for UNIX and Linux?

Q: APPEND a list of users currently logged in to the file "userlog". Do not overwrite the file.
A: who >> userlog / w >> userlog / finger >> userlog

Q: What is the maximum number of logical partitions that a disk can have? (Assume MBR)
- One
- Two
- Four
- Ten
- None of these
A: One

Q: Write a command to move non-hidden files in your current directory that end in non-digits to the directory "myfiles", which is the parent directory of your current directory.
A: mv *[!0-9] .. / mv *[!0-9] ./.. / mv *[!0-9] ../ / mv ./*[!0-9] ../ / mv ./*[!0-9] .. / mv -i *[!0-9] ..

Q: What is the main programming language used in the Linux Kernel?
A: C
If wrong: C is the main programming language used in the Linux Kernel.

Q: Remove all files in your current directory that start with an uppercase LETTER and end in a lowercase letter. Have the system prompt you before it deletes each file. Assume LC_COLLATE=C, so you have case sensitivity turned on.
A: rm -i [A-Z]*[a-z] / rm -i ./[A-Z]*[a-z] / rm -i [ABCDEFGHIJKLMNOPQRSTUVWXYZ]*[abcdefghijklmnopqrstuvwxyz]

Q: Using wildcard(s), remove the files "blue1", "blue2" and "blue3" from your parent directory which is called "dad". Do not remove any other files including blue4, blue11 and blue20.
A: rm ../blue[1-3] / rm ../blue{3,1,2} / rm ../blue[123] / rm ./../blue{1,2,3} / rm -i ../blue[123] / rm ../blue{1,3,2} / rm ../blue{1,2,3} / rm -i ../blue{1,2,3} / rm -i ../blue[1-3]

Q: From your current session, without logging out or using the ssh command or opening another window, login as c121111.
A: su - c121111 / su c121111

Q: Copy the text file "stuff" to file "morestuff".
A: cat stuff > morestuff / cp stuff morestuff

Q: Place the contents of files filea, fileb, and filec into file fileabc. Use one command.
A: cat filea fileb filec > fileabc / cat file{a,b,c} > fileabc / cat file[a-c] > fileabc / cat filea fileb filec >> fileabc / cat file[abc] > fileabc / cat file[a-c] | > fileabc

Q: Write a command that reports how many hidden and non-hidden files and directories you have in your current directory.
A: ls -a | wc -l / ls -la | wc -l / ls -al | wc -l / ls -a | wc -w / ls -a1 |wc -l

Q: Count the number of characters in file1.
A: cat file1 | wc -c / more file1 | wc -c / wc -c file1 / wc -c < file1 / wc -m file1

Q: Find all lines in the file "great_teams" that have the pattern "UM" in them.
A: grep UM great_teams / more great_teams | grep UM / cat great_teams | grep UM / grep UM 'great_teams' / grep "UM" great_teams / wc -w UM great_teams / cat great_teams|grep "UM" / grep 'UM' great_teams

Q: Given the command: mv f1 f2 > f3 what ends up in f3?
A: nothing / Nothing. / Nothing. The way the command is set up now, the output from the move function gets put into f3, but since it is only a move function, there is no output. f3 will be created, but won't have anything in it.

Q: The file "nolink" is in your parent directory. The parent directory is called "mom". Create a link to "nolink" called "alink". It should be in your current directory. The name of your current directory is "myplace".
A: ln ../nolink alink / ln ../nolink ./alink

Q: Assuming that you are in command mode in vi, how do you delete 34 lines? (Do not type the command 34 times.)
A: 34dd

Q: Assuming that you are in command mode in vi, how do you merge your current line and the one below it?
A: J / uppercase j / J (uppercase) / capital J / upper J / J (shift + j)

Q: Assuming that you are in command mode in vi, how do you exit while saving to a new file called "new"?
A: :x new / :wq new

Q: Assuming that you are in command mode in vi, how do you insert a new line above your current line and get into insert mode at the same time? (A single command, not several)
A: O / O (uppercase) / O - uppercase O / O uppercase / An uppercase O / O (uppercase O) / capital O / uppercase O

Q: Assuming that you are in command mode in vi, how do you move to line 53? (A single command, not several)
A: 53G

Q: Given the directory structure on the board and without changing directories: From the starting directory, create two files in d5 called f1 and f2.
A: touch d2/d5/f1 d2/d5/f2 / touch d2/d5/f{1,2} / touch ./d2/d5/f1 ./d2/d5/f2 / touch d2/d5/{f1,f2} / touch ./d2/d5/f{1,2}

Q: Given the directory structure on the board and without changing directories: Assuming that you are in the starting directory, write a command to copy the f1 file in d5 to d2.
A: cp d2/d5/f1 d2/f1 / cp d2/d5/f1 d2 / cp d2/d5/f1 ./d2 / cp d2/d5/f1 ./d2/f1 / cp ./d2/d5/f1 ./d2 / cp -i d2/d5/f1 d2 / cp d2/d5/f1 d2/ / cp ./d2/d5/f1 ./d2/ / cp ./d2/d5/f1 ./d2/f1

Q: Given the directory structure on the board: Assuming that you are in the starting directory, write a command to make d6 your current directory.
A: cd d2/d6 / cd ./d2/d6 / cd d2/d6/

Q: Given the directory structure on the board and without changing directories: From d6, copy f2 (which exists and is in d5) to d2, calling the new file f2a.
A: cp ../d5/f2 ../f2a

Q: Given the directory structure on the board and without changing directories: From d6, move f2a from d2 to the starting directing. (That's the top of the diagram.)
A: mv ../f2a ../.. / mv ../f2a ../../ / mv ../f2a ../../f2a