Professional Documents
Culture Documents
Ex01Review F2015-ANS
Ex01Review F2015-ANS
Ex01Review F2015-ANS
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.
_________________________________________________________
1 of 10
CENT 228
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."
2 of 10
CENT 228
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
load ~/.bashrc
bash ~/.bashrc
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
load ~/.bashrc
bash ~/.bashrc
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
d. echo REDHAT
3 of 10
CENT 228
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?
* ? [ ] [^
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
alias
alias_name="command options"
4 of 10
CENT 228
27. Write a set of commands that can be used on one line to run the command
echo "I found it"
completes successfully.
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?
5. What does the tilde (~) character represent? Represents the user's home directory.
Is it absolute or relative?
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?
5 of 10
CENT 228
The R switch supports performing the specified operation recursively on all of the subdirectories and files in the
specified directory location.
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
6 of 10
CENT 228
e. mv test .
f. mv test ..
g. mv test ~
h. mv test /
i. mv test /sysadmin
j. mv test /etc
EX01REVIEW.F2015-ANS.DOCX
7 of 10
CENT 228
k. mv test
l. mv test ~/bottom
<
> or >> or |
5. **How do you redirect the output from error messages from a command?
2> or 2>>
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
8 of 10
CENT 228
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.
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.
EX01REVIEW.F2015-ANS.DOCX
9 of 10
CENT 228
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
EX01REVIEW.F2015-ANS.DOCX
10 of 10