Ex01Review F2015-ANS

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

CENT 228

REVIEW FOR WRITTEN EXAM 01

EXAM PREP SUGGESTIONS

Complete/review project assignments 1-9. There are review questions included that may be representative of
questions that could be included on the exam. Most of those have been included below.

The questions provided below are intended to help in the review process by jogging your memory about aspects you
may have overlooked, or forgotten. The exam will NOT cover all of these details, but material covered on the exam
will (most likely) be based on this list of topics.

Important concepts or details that might be unclear are also indicated with ** below.

PR01: INSTALLING LINUX


1. What does CentOS stand for?

_________________________________________________________

PR02: LINUX INTRODUCTION


1. Name the graphical text editor available in the GNOME desktop environment. _______________________
2. What is a text editor? How is a text editor different from a word processor?
A text editor allows you to edit text only data without adding any special formatting codes. Text editors are needed
for writing program source code, html code, and other kinds of code that will not be able to process or use additional
formatting features.
A word processors allows you to edit text and to add formatting features, such as bold, italics, etc. These kinds of
features can only be implemented if the word processor adds special coding to indicate the features being used. Word
processors like MS Word encode these features using proprietary binary coding methods that cannot be viewed in a
text editor. This type of coding cannot be processed by compilers and interpreters because the additional coding does
not conform to the syntax requirements of the compiler/interpreter.
3. **What is a virtual console? How do you access virtual consoles?
A virtual console is a standalone command-line based user interface, comparable to the "dumb" terminals formerly
used with mainframe and mini computers. In a Linux installation that boots automatically to a graphical user
environment known as a Desktop, you can access a virtual console by use the key sequence CTRL-ALT-Fx where Fx
refers to one of the function keys. Typically, virtual consoles are accessible using the function keys F1 to F6, but this
can be modified via configuration. In CentOS, the first console is actually used by the graphical user interface, so is
not available as a virtual console.
4. **What is a graphical console? How do you access the graphical console?
A graphical console is a console that provides a graphical user interface, or Desktop, similar to Windows and other
graphical environments. In CentOS, the first console is allocated to the graphical user interface (GUI). In
openSUSE, the graphical user interface is normally configured to run on the seventh console (F7), which means all of
the first 6 consoles are available for use as text-based virtual consoles. You can access the graphical console by using
the key sequence CTRL-ALT-Fx where Fx is the function key that corresponds to the console that runs the graphical
interface. In CentOS, that is CTRL-ALT-F1. In openSUSE, it is CTRL-ALT-F7.
5. **What is terminal (or console) window? How do you open a terminal window?
A terminal window, or console window, refers to a text-based command window that you open in the graphical
desktop environment. You open a terminal window in Linux by using the Application menu (CentOS) or right-clicking
on the desktop and opening a terminal from there. Opening from the Desktop means that you will be in the Desktop
subdirectory of your user account, instead of the home directory for the user account, so is not necessarily the most
efficient way to get to where you want to be.
6. What command can be used to identify which users have logged onto the computer? ______________________
EX01REVIEW.F2015-ANS.DOCX

HONOLULU COMMUNITY COLLEGE

1 of 10

CENT 228

REVIEW FOR WRITTEN EXAM 01

7. What command can be used in a command line environment to view the contents of a directory? _______________
8. What commands can be used in a command line environment to view the contents of a text file? _______________
9. What happens if you try to view the contents of a binary file in a command line environment using the cat command?
10. What is vim?
The Linux "improved" version of the traditional Unix command line text editor called vi. It is a modal text editor,
which means you can do different things in different modes. There is a graphical version of vim that can also be
installed for use in a graphical environment. Note the graphical version of vim is not installed automatically.
11. What is the man command and why is it useful?
12. Apart from the man command, describe (at least) two other help methods that are available for Linux.
13. **What requirement is imposed by the GNU General Public License (GPL) and how does it apply to Linux?
The GPL requires that any modifications to the source code for GPL licensed software must be freely available to
users of the (modified) software, so the users can add their own customizations if desired. This is called the "copyleft"
provision of the GPL, since the GPL requirement is inherited by all modifications to the software. So, there is no
"privacy" IF the software is distributed and made available to other users. If the person who modifies the code uses it
for his/her own exclusive use and does not provide the software to anyone else, there is no requirement to make the
changes publicly available.
Note the GPL only establishes requirements for availability of the source code. It does NOT establish any
requirements related to distribution of compiled binaries for GPL licensed software and it does NOT prohibit
charging a fee for distributing the source code!
Note that the word "free" as used in the GPL means that the source code is available to users so they can make their
own modifications as in users have the freedom to modify the software. The word "free" in this context does not
mean it has be distributed without monetary compensation, as in "free beer."
See the following Wikipedia article for more discussion of terms and conditions of the GPL license:
https://en.wikipedia.org/wiki/GNU_General_Public_License#Terms_and_conditions
See also the GPL version 2.0 itself, which is the version that applies to the Linux kernel:
https://gnu.org/licenses/old-licenses/gpl-2.0.txt
Verbatim excerpt from GPL version 2.0 Preamble:
" When we speak of free software, we are referring to freedom,
General Public Licenses are designed to make sure that you have
distribute copies of free software (and charge for this service
that you receive source code or can get it if you want it, that
the software or use pieces of it in new free programs; and that
can do these things."

not price. Our


the freedom to
if you wish),
you can change
you know you

Verbatim excerpt from GPL version 2.0 Terms and Conditions:


" 1. You may copy and distribute verbatim copies of the Program's source code
as you receive it, in any medium, provided that you conspicuously and
appropriately publish on each copy an appropriate copyright notice and
disclaimer of warranty; keep intact all the notices that refer to this License
and to the absence of any warranty; and give any other recipients of the
Program a copy of this License along with the Program.
You may charge a fee for the physical act of transferring a copy, and you may
at your option offer warranty protection in exchange for a fee."
EX01REVIEW.F2015-ANS.DOCX

HONOLULU COMMUNITY COLLEGE

2 of 10

CENT 228

REVIEW FOR WRITTEN EXAM 01

14. Linux is based on what previous operating system?


15. **Linux is issued under which software license?

Gnu General Public License (GPL)

16. **What are the advantages of a command line environment compared to a graphical environment?
a. Faster processing no GUI to use up resources displaying graphics and menus
b. More secure less code being used (no GUI) means fewer bugs to be exploited to attack the system.
PR03: LINUX SHELL
1. **What is a shell?
A shell refers to a "command shell" environment. A command shell is a process running on the computer that
presents a command prompt to the user and waits for user input. When the user enters a command, the shell reads
that command, creates a subordinate shell environment and executes (execs) the new command in that subshell. The
parent shell waits while the command executes and when the command finishes, the parent shell collects its return
value and releases the other environment resources (memory, etc) back to the CPU for reuse. Examples of command
shells include the command window in Windows, the virtual console environments in Linux/Unix, the terminal
windows used in the Linux graphical environment. (We will probably revisit this concept in more detail later when we
discuss processes.)
2. What is the default shell for user accounts in Linux? (Select the best answer.)
a. /bin/bash

b. /bin/zysh

c. /bin/ksh

d. /bin/tcsh

3. **What user level configuration files for customizing the bash shell are located in the user's home directory
(CentOS)?
~/.bash_profile , ~/.bashrc, ~/.bash_logout
4. **Which of the following files are sourced when you start a subshell after having already logged in?
a. ~/.bash_profile

b. ~/.profile

c. ~/.bashrc

d. /etc/profile

5. **Which shell configuration files are sourced when you start a new login session?
Both the ~/.bash_profile and the ~/.bashrc files are sourced when you start a new login session (CentOS).
6. Which of the following configuration files could you edit to create an environment variable that must exist in all
shells that are started by users on your system?
a. ~/.profile

b. /etc/profile

c. ~/.bash_login

d. ~/.bashrc

7. **You have just edited your ~/.bashrc file and added a line that loads a variable. Which of the following commands
can you use to re-run the ~/.bashrc file within your current shell? (Choose all that apply.)
a. Run the command:

. ~/.bashrc

c. Run the command:

load ~/.bashrc

b. Run the command:

bash ~/.bashrc

d. Run the command:

source ~/.bashrc

8. **You have just edited your ~/.bashrc file and added a line that loads a variable. Which of the following commands
can you use to run the ~/.bashrc file in a subshell? (Choose the best option.)
a. Run the command:

. ~/.bashrc

c. Run the command:

load ~/.bashrc

b. Run the command:

bash ~/.bashrc

d. Run the command:

source ~/.bashrc

9. **Which of the following commands can be used to view the value of a shell (local) variable REDHAT in Linux ?
a. echo %REDHAT%

EX01REVIEW.F2015-ANS.DOCX

b. echo $REDHAT

c. echo $redhat

HONOLULU COMMUNITY COLLEGE

d. echo REDHAT

3 of 10

CENT 228

REVIEW FOR WRITTEN EXAM 01

11. Give a command you could use to create a variable called TEST with the value "Testing, 1, 2, 3, 4, "
(Give a complete example of a command, not just a name.)
TEST="Testing, 1, 2, 3, 4, "
12. **Would the variable TEST that you created above be available to child processes in subshells? NO
13. **What would you need to do to ensure that this variable would be inherited by subshells? Export it
14. **The appropriate file to create (or modify) user defined environment variables is ~/.bash_profile (in CentOS)
15. **The appropriate file to create user defined shell (local) variables is ~/.bashrc (in CentOS)
16. How can a shell (local) variable be promoted to an environment variable?

By exporting it

17. **Which of the following files is appropriate for storing the users locally defined aliases to be initialized each time a
new shell is started? (Choose the best answer for CentOS.)
a. /etc/profile

b. ~/.aliases

c. ~/.bashrc

d. /etc/bash.bashrc

18. **Which of the following notations can be used to prevent the $ character in the phrase $DIR from being interpreted
as a special character by the bash shell? (Choose all that apply.)
a. \$DIR

b. '$DIR'

c. -$DIR

d. "$DIR"

19. **Which of the following notations can be used to permit the $ character in the phrase $DIR to be interpreted as a
special character by the bash shell? (Choose the best answer.)
a. \$DIR

b. '$DIR'

c. $DIR

d. "$DIR"

20. Which of the following output redirection symbols will not overwrite an existing file?
a. >

b. <

c. <<

d. >>

17. To which device file can you redirect stderr output in order to ignore it completely? _______________________
18. What characters have special meaning to the shell (metacharacters)?
What are they used for?

* ? [ ] [^

(spaces used to separate)

Used as wildcards and range expressions for file name globbing

19. **What is a shell variable? A local variable that is visible to the current shell only.
What would you use it for? Use to customize your shell environment or to store values at a particular time.
20. What is an environment variable?
A variable that has been "exported" so it is visible to the current shell and all of its subshells.
What would you use it for?
Examples include (1) customizing your command PATH by modifying the ~/.bash_profile file, so it will always
recognize additional directories as storing executable files, or (2) creating variables in the current shell that you want
to use with scripts or commands that will be executed to run in subshells. If you want an environment variable to be
persistent to new shells, you should define it and export it in the ~/.bash_profile file.
21. How do you access (display) the contents of a shell or environment variable?

echo $variable_name

22. **What environment variable contains the current user's default search path?

PATH

23. What return value indicates that a process completed successfully (without errors)?
24. **What information does a child process inherit from the shell that creates it?
25. What is an alias?

0 (zero)

environment variables

A way to create a customized form of a command, useful for frequently used commands

26. How can you create aliases?


EX01REVIEW.F2015-ANS.DOCX

alias

alias_name="command options"

HONOLULU COMMUNITY COLLEGE

4 of 10

CENT 228

REVIEW FOR EXAM 1 WRITTEN

27. Write a set of commands that can be used on one line to run the command
echo "I found it"

only if the command

grep localhost /etc/hosts &&

grep localhost /etc/hosts

completes successfully.

echo "I found it"

28. What command accepts input from stdin and sends it to both a file and stdout at the same time?

_________

29. Provide the complete command needed to create an alias named cls to run the clear command in your current shell?
alias cls=clear
30. For each of the following, give at least one example of a sequence of commands that will appear on one line to:
a. Unconditionally run multiple commands from the same command line? ________________________________
b. Run a second command on the command line, only if the first command is successful?
c. Run a second command on the command line, only if the first command is NOT successful?
d. Run a command, or a sequence of commands, in a subshell so that the side effects of the command do not affect
the current shell?
(Use parentheses around the sequence of commands to be run in a subshell)
PR04: FILES AND DIRECTORIES
1. **Which of the following are absolute pathnames? (Choose all that apply)
a. ../bin

b. /home/bin

c. /

d. bin

e. ~/toplevel

f.

./toplevel

f.

./toplevel

2. **Which of the following are relative pathnames? (Choose all that apply)
a. ../bin

b. /home/bin

c. /

d. bin

e. ~/toplevel

3. The files associated with an ordinary user's account (e.g., sysadmin) are stored in which directory by default?
/home/username
4. *How is a directory file different from an ordinary file?

A directory file contains the NAMES of other files and directories.


An ordinary file contains data.

5. What does the tilde (~) character represent? Represents the user's home directory.
Is it absolute or relative?

~ expands to /home/username, so is an absolute reference to the user's home directory.

6. Write the complete form of the ls command you can use to view a long listing of the files in your current directory,
including hidden files?
7. Which command can be used to remove a directory and all of the files within it, including subdirectories?

Why is this command dangerous?


8. What information does the pwd command provide? The absolute path to the current directory.
9. What command could be used to create an empty file named test ?
10. Give a complete command that can be used to view the first several lines of all of the files in the /etc directory, but
not in its subdirectories.
head *
11. Give a complete command can be used to view the last several lines of all files in the current directory, but not in
subdirectories.
12. What command is used to rename files or directories?
13. What is the effect of the R switch when used with file management commands? (File management commands
include ls, cp, mv, rm)
EX01REVIEW.F2015-ANS.DOCX

HONOLULU COMMUNITY COLLEGE

5 of 10

CENT 228

REVIEW FOR EXAM 1 WRITTEN

The R switch supports performing the specified operation recursively on all of the subdirectories and files in the
specified directory location.

Sample exercises for practicing mv


Given the following file structure (where directory names end with / and file names do not) write on the original structure
for each problem to show the resulting file structure after executing the given mv command, starting from the top
directory.
For each question, the current directory is always /home/sysadmin/top/, i.e. if you use the pwd command, the output
would be:
#sysadmin> pwd
/home/sysadmin/top

For each of the following exercises, always start with the initial directory
structure shown to the right and apply the mv command to the directory tree
shown. In each case, indicate what the file structure should look like after the
command has been applied. Its ok to cross out, write over, etc. as a means of
indicating the changes that would occur.
For all of these questions, assume you have root permissions i.e., you are
logged in as root or have been given the necessary permissions to create files
outside of the sysadmin home directory.
a. mv test home

b. mv test bottom

c. mv test mid

d. mv test top

EX01REVIEW.F2015-ANS.DOCX

HONOLULU COMMUNITY COLLEGE

6 of 10

CENT 228

REVIEW FOR EXAM 1 WRITTEN

e. mv test .

f. mv test ..

g. mv test ~

h. mv test /

i. mv test /sysadmin

j. mv test /etc

EX01REVIEW.F2015-ANS.DOCX

HONOLULU COMMUNITY COLLEGE

7 of 10

CENT 228

REVIEW FOR EXAM 1 WRITTEN

k. mv test

l. mv test ~/bottom

PR05: REDIRECTION AND FINDING FILES


1. What are the 3 standard file streams that are created automatically whenever you open a shell?
STDIN, STDOUT, STDERR
2. What file handles (numbers) are automatically associated with each of the standard file streams? 0, 1, 2
3. **How do you redirect input to a command?

<

4. **How do you redirect the normal output from a command?

> or >> or |

5. **How do you redirect the output from error messages from a command?

2> or 2>>

6. **What is meant by the PATH?


The command search PATH. The list of directories the operating system will check to look for executable (command)
files.
7. Which commands can be used to locate files within the PATH? which, whereis, type
8. **Which commands can be used to locate files, even if they are not located within the PATH?

find, locate

9. Which command performs a real-time search of files on the system to locate specified files?
10. Which command searches a database of files to find specified files?
11. Which command searches for files that match specified criteria? find
12. Be able to construct find commands to match specified criteria and to perform ls and exec options on the results of
the find. (I.e., know the syntax for specifying criteria and options for the find command.)
PR06: GREP AND REGULAR EXPRESSIONS
1. Provide a grep command including options that could be used to search the /etc directory and its subdirectories for
lines that start with 127.0.0.1?
2. Use grep to search for files in the /etc directory and its subdirectories that contain a United States extended zip code,
written using the pattern #####-####, where each # represents a numeric digit. Any characters that appear
immediately before or after the zip code should NOT be numeric digits or hyphens (-).
3. Use grep to search for files in the /etc directory, but not its subdirectories, that contain a telephone number using the
pattern 1-###-###-###, where each # represents a numeric digit. Any characters that appear immediately before
or after the zip code should NOT be numeric digits or hyphens (-).
4. **Provide regular expressions that would match a character string containing specified patterns, such as those given
above.
EX01REVIEW.F2015-ANS.DOCX

HONOLULU COMMUNITY COLLEGE

8 of 10

CENT 228

REVIEW FOR EXAM 1 WRITTEN

5. ** Which characters have special meaning for regular expressions (REGEX metacharacters)?
a. Which of these characters have the SAME meaning as shell metacharacters (i.e., the character is used to mean the
same thing for both shell interpretation and for REGEX interpretation. [ ]
b. Which REGEX metacharacters have DIFFERENT meanings when used with REGEX instead of filename
globbing? *, ?
c. Which REGEX metacharacters do NOT have special meaning for filename globbing?

. + {}

d. Which REGEX metacharacters require the use of extended grep instead of ordinary grep? (I.e., the characters are
defined as extended regular expressions).
e. What is the meaning of "*" to the shell?
Wildcard to represent any sequence of characters, including the empty string.
f.

What is the meaning of "*" when used in regular expressions?


Zero or more repetitions of the previous character, or grouping if parentheses are used.

PR08: SCRIPTS

1. **Describe the differences between sourcing a script and executing a script. (I.e., briefly describe what
happens when you source a script and what happens when you execute a script.)
When a script is sourced, it is run in the current shell, which means there may be side effects of running the
script. For example, the bash configuration files ~/.bash_profile and ~/.bashrc are sourced when you open
a new login shell to set your customized shell environment. This is a side effect that would not happen if
these files were executed. So, you WANT shell configuration files to be sourced in the current shell.
When a script is executed, it is run in a non-interactive subshell. This means that environment variables
from the current shell will be inherited and visible (usable) to the script, but because the script is run in a
subshell there will be no "side effects" in the current shell, such as inadvertently changing your directory
location. Naturally, if you run the cd command, it will change your directory location because that is the
purpose of the particular command.
2. What requirements must be met for a script to be executed? (I.e., if these requirements are not met, you
would get an error if you tried to execute the script.)
The script must be executable that means the execute permission bit is set.
Also, you must provide either a valid relative or absolute path to specify the location of the script, unless
you know that the location can be found in your command search PATH variable.
3. **Describe the differences between using shell variables and environment variables with scripts. (I.e., when
CAN you use shell variables with a script? When CAN you use environment variables with scripts?)

You can use shell variables if a script is to be sourced, but not if it is to be executed.
You can use environment variables regardless of whether the script will be sourced or executed.

4. What would be the effect of the following line in a script?


echo "The present working directory is `pwd`"
The absolute path for the present working directory will be displayed in the statement
"The present working directory is ."
5. **What notation is used to display (dereference) the value of a shell or environment variable in Linux?
6. What notation is used to read the values provided through command line arguments in a shell script in bash?

$1 is the first command line argument


$2 is the second command line argument

EX01REVIEW.F2015-ANS.DOCX

HONOLULU COMMUNITY COLLEGE

9 of 10

CENT 228

REVIEW FOR EXAM 1 WRITTEN

$n would be the nth command line argument, if present.

7. What is the general syntax for an if statement in bash?


8. What is the general syntax for a for loop in bash?
9. What is the general syntax for a while loop in bash?
10. What command is used as the basis for creating test conditions in bash?

test or [ ] as a short form.

PR09: ARCHIVING AND COMPRESSION


1. Which of the following archiving utilities can be run in a command line environment? (Select all that apply.)
a. cpio

b. ark

c. tar

d. dd

2. **What tar command could you use to create a gzip-compressed archive file called /root/optfile.tar.gz that contains
the entire contents of the /opt directory? (Assume you are logged in as root.)
tar czf /root/optfile.tar.gz

/opt

3. **What tar command could you use to create a bzip2-compressed archive file called /root/optfile.tag.bz2 that
contains the entire contents of the /opt directory? (Assume you are logged in as root.)
tar cjf /root/optfile.tar.gz

/opt

4. If you download a file with a .tgz extension, what command(s) could you use to extract the contents of the file?
tar xzf filename.tgz

OR

gunzip filename.tgz followed by tar xf filename.tar (if the tar extension is present)

5. After downloading a file, you note that it has a .bz2 extension. What command(s) could you use to extract the
contents of this file?
bzip2 d filename.bz2

OR

bunzip2 filename.bz2

6. What is the effect of using the C switch in the following command?


tar xvzf test.tgz -C /tmp
The current directory will be changed to /tmp BEFORE the test.tgz file is extracted. This is the ONLY way to specify
that the specified file should be extracted into a DIFFERENT directory than the one you are in when you enter the
command. The only other option is to change to the directory where the file should be extracted, then enter the
command to extract the tar file specifying the present location using an absolute path.

EX01REVIEW.F2015-ANS.DOCX

HONOLULU COMMUNITY COLLEGE

10 of 10

You might also like