Chapter 2 Flashcards
What’s the standard Linux shell?
Ha! It’s both a command line interpreter and a programming language
How do we check the exit status? (print it to the command line)
echo $?
How do we search for a term within a man page?
/ (forward slash) term (e.g. /nana) and then ‘n’ for next entry ahead ‘N’ for next entry behind
How to search for a specific keyword?
man -k wordToSearch
What are info pages and how are they different from man pages? How do you get around there?
They are additional documentation with more robust capability and detail than man. You can enter into page, hit next and previous with ‘n’ and ‘p’ keys
How to count the number of lines in a file?
wc -l file.txt
How to count the total number of characters in a file?
wc -m file.txt
How to count the number of characters on the longest line in a file?
wc -L file.txt
How to append some stuff to an existing file?
use»_space; file.txt (rather than ‘>’)
How do we view all files that start with a dot?
ls -a
How do we view all files?
ls -all
How do we view a more detailed listing of files, including their sizw?
ls -lh
How do we handle variables in shell?
We do not have to store them anywhere - just declare them in a window, like so:
test_var=”this is a var”
To show it, do
echo $test_var
How do we display a home directory?
$HOME
Which variable shows the user’s home directory?
$HOME
Which variable is the primary prompt string?
$PS1
Which variable is a colon-separated list of directories where the shell looks for commands?
$PATH
How can we store the contents of a “list files” command in a variable?
var1=$(ls)
How are bash single quotes different from double quotes?
Single quotes ‘ preserve the literal value of every character contained within the quotes, including the escape character
Double quotes ‘’ preserve the literal value of most characters contained within the quotes, exceptions include $ for variables, ‘ for single quoting, and \ for escaping a character
What is an escape character, what does it do?
A non-quoted backslash \ is the bash escape character; it preserves the literal value of the next following character, with the single exception of newline
How do we change the current directory to the user’s home directory?
cd ~
How do we print the current directory?
pwd
Show the list of users currently logged in to the system
w
How to append something to the path variable? or any other variable, same difference
PATH=”$PATH:$HOME/scripts
What does the source command do in Bash?
The source command reads and executes commands from the file specified as its argument in the current shell environment