IT 350 Quiz 1
Given the history list from Figure 2.3, what command is recalled with each of the following?!! | !5 | !ls | !cd | !c
!! - Repeats the last command. !5 - Executes the 5th command in history. !ls - Runs the most recent ls command. !cd - Runs the most recent cd command. !c - Runs the last command starting with c.
You want to reexecute the last instruction you entered in your Bash session. Describe three ways to do this.
!!, ! -1, or using the up arrow key.
How does the operator >> differ from the operator >?
> overwrites a file, while >> appends to it.
From your Bash shell, you type bash. After working for a while, you type exit. What happens?
A new shell session starts; exit closes that session, returning to the original shell.
Parameters
Additional arguments for commands.
Prompt
Bash command-line interface indicator.
Why is Bash an interpreted environment rather than a compiled one?
Bash executes commands in real-time without needing prior compilation, allowing flexibility and interactivity.
What is the history of the Bash shell?
Bash is an improvement on the Bourne shell, developed for the GNU Project in 1989 by Brian Fox, incorporating features from C Shell and KornShell.
Name three compiled languages.
C, C++, Java
What does history -c do?
Clears the command history.
What does the synopsis portion of a man page tell you? If you are not sure, try man ls, man mount, and man ip as examples and see what you get.
Command syntax and usage format.
Redirection (**, **, **, **)
Controls input/output of commands.
Compiler
Converts source code into executable programs.
PS1 variable
Customizable prompt definition.
Bash
Default Linux shell, short for Bourne Again Shell.
Java Virtual Machine (JVM)
Executes Java byte-code
Man pages
Help documentation for Linux commands.
Byte code
Intermediate compiled form for languages like Java.
Why do we refer to the user's environment as a shell?
It encapsulates the user's command-line interface and interactions with the operating system, like a shell surrounding the kernel.
Command line editing
Keystrokes to modify commands in Bash.
Wildcard (``)
Matches file patterns
Options
Modify command behavior, e.g., ls -a lists hidden files.
Match the following command line editing function with the keystroke that provides it Move the cursor to the end of the line i. c+k Move back one character ii. c+_ Move forward one word iii. c+e Delete one character iv. m+f Retrieve the last instruction entered v. c+b Undo the last keystroke vi. c+d Delete all characters from here to the end of the line vii. c+p
Move cursor to end of line → c+e Move back one character → c+b Move forward one word → m+f Delete one character → c+d Retrieve last instruction → c+p Undo last keystroke → c+_ Delete to end of line → c+k
C-Shell
Older Unix shell predating Bash.
Provide an instruction to alter your prompt so that it displays the following information: (time : instruction number) [username] prompt character as in (10:04 am : 31) [foxr] $
PS1='( : \!) [) [\u] \$ '
Interpreter
Processes and executes user commands in a shell.
Name three interpreted languages.
Python, Ruby, Bash
Pipe (``)
Redirects output from one command to another.
Alias
Shortcut for Linux commands. Example: alias ll='ls -al'
STDERR, STDIN, STDOUT
Standard error, input, and output channels
Bash session
Stores command history, variables, and aliases.
History list
Stores last 1000 commands, accessible via history.
Environment variable
System-defined variables like $HOME, $PWD.
What is the difference between cat file1.txt file2.txt file3.txt and cat file1.txt file2.txt > file3.txt?
The first outputs all three files to the screen, the second concatenates the first two files into file3.txt.
Home directory (~)
User's main directory, represented as ~.
TC-Shell
Variation of C-Shell with added features.
Given the following prompt, answer the questions below. [zappaf@frenchie /etc]# Who is logged in? Is the user logged in as themself or root? What is the current working directory? What is the hostname?
Who is logged in? zappaf Is the user root or a regular user? Root (indicated by # in the prompt) What is the current working directory? /etc What is the hostname? frenchie
Write the command to define as an alias ... to move you up two directories.
alias ..='cd ../..'
Write the command to define as an alias stuff to perform a long listing of your home directory.
alias stuff='ls -al ~'
What is the difference between the arch command and the uname command?
arch displays the system architecture, while uname provides detailed OS and kernel information.
Provide an example of why you might use << as a form of redirection.
cat << EOF > file.txt Hello World EOF
Assume the variable AGE stores 21. What is the output for each of the following? echo AGE | echo $AGE | echo $age | echo \$AGE | echo $AGE\!
echo AGE → AGE echo $AGE → 21 echo $age → Blank (variable not set) echo \$AGE → $AGE echo $AGE! → 21!
Assume that foxr is logged in to a Linux computer on console and user zappaf is logged into the computer remotely from IP address 1.2.3.4. What would the command who show?
foxr tty1 MM-DD HH:MM zappaf pts/1 MM-DD HH:MM (1.2.3.4)
You type ls and you receive 3 columns worth of file names. You want to see the output as a single column listing. What can you do?
ls -1
You want to perform a recursive listing using ls. What option(s) would you specify?
ls -R
What is the difference between ls -a and ls -A?
ls -a lists all files, including . and .., while ls -A omits . and ...
Provide an instruction to redirect the output of ls -l to the file ~/listing.txt.
ls -l > ~/listing.txt
What is the difference between ls -l and ls -L?
ls -l provides a long listing, ls -L follows symbolic links.
Long listing
ls -l provides detailed file information.
The following instruction does not do what we expect in that we want to output the word count for the items listed in the current directory. What does it do and how can you fix it? ls > wc
ls > wc tries to write the output of ls to a file named wc. To count words, use ls | wc.
Define a variable to store your first initial, your middle initial, and your last name. Include proper spaces and punctuation.
name="J.D. Doe"
What command would you use to change your password?
passwd
What command would you use to find out your current working directory?
pwd
Explain why wc < somefile does not require the < operator.
wc somefile implicitly reads from the file without redirection.
What command would you use to determine your username?
whoami
Explain the role of the following characters as used in Bash. ~ ! - *
~ → Represents the user's home directory. ! → Used for command history recall (!!, !n). - → Represents the previous working directory (cd -). * → Wildcard for matching multiple filenames.