Chapter 3: Command Line Fun Flashcards
How do you view the PATH variable?
echo $PATH
How do you view the USER variable?
echo $USER
How do you view the HOME variable?
echo $HOME
What is the export command?
The export command defines a variable.
Why is the export command useful?
If we don’t want to repeatedly type out some sort of string, for example an IP address, the export command allows us to define a variable.
How do you define a variable using export?
E.g. export b=192.168.116.114
How do you then use that variable in a practical example?
ping -c 10 $b
The variable must have a $ accompanying it.
What command and variable do we use to view the current PID (Process ID) of the bash shell?
echo “$$”
How do we view all environment variables?
env
How do we view command history?
history
After viewing the history, what is a fast way to execute a command?
Using the numbers next to the command, type !3 (for example).
Where is all command history saved?
In the .bash_history file.
What two variables dictate the command history save?
HISTSIZE and HISTFILESIZE
What does HISTSIZE do?
Controls the number of commands kept for the current session.
What does HISTFILESIZE do?
Configures how many commands are kept in the overall history file.
Where are HISTSIZE and HISTFILESIZE stored?
.bashrc - bash configuration file
How do we use the reverse-i-search facility?
Ctrl + R
What are the three data streams connected to the programs run through bash?
Standard Input (STDIN) Standard Output (STDOUT) Standard Error (STDERR)
How is piping related to the data streams?
Piping connects the data streams between programs and files.
What command counts the words and lines of a document?
wc
What is the command for counting the number of lines in a document?
wc -l
What is the command for counting the number of characters in a document?
wc -m
How do you create a new document through redirecting data streams?
echo “hello bob” > redirection.txt
How do you append data using data streams?
echo “hello jane”»_space; redirection.txt
What are the file descriptors for STDIN, STDOUT and STDERR respectively?
0, 1 and 2 respectively.
How do we redirect error messages?
After a command, use 2>error.txt as an example.
Another example is 2>/dev/null - which is a file used for discard error output.
What is an example of piping a command?
cat error.txt | wm -m > count.txt
What does the grep command do?
Searches for a line containing a given string of text.
What does the i switch for grep do?
Ignores text case in strings.
What does the r switch for grep do?
Searches recursively through a file or directory.
What does sed do?
sed is a stream editor that performs editing functions on a stream of text.
Use an example of the sed command and explain the components.
echo ‘I need to try hard’ | sed ‘s/hard/harder/’
The single quote starts the argument. s means substitute, hard is the word to replace and harder is the word to replace it with.
What does the cut command do?
The cut command extracts a section of text from a line and outputs it to standard output.
What does the d switch do in cut?
The d switch defines the delimiter.
What does the f switch do in cut?
The f switch defines the field number of the line to cut.