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
What’s stored in the /boot directory?
Standard boot files
What’s stored in the /dev directory?
Device files
What’s stored in the /etc directory?
Configuration files
What’s stored in the /mnt directory?
Temporary mount points
What’s stored in the /opt directory?
Optional packages
What’s stored in the /proc directory?
Kernel and process files
What’s stored in the /root directory?
Root user home directory
What’s stored in the /run directory?
Application state files
What’s stored in the /sbin directory?
System administrator binaries
What’s stored in the /srv directory?
Service data
What’s stored in the /usr directory?
User ginaries
What’s stored in the /var directory?
Variable data files
What’s stored in the / directory?
Root directory
how do we go to the previous directory location?
cd -
Which ls flag sorts files by the last time the file was modified, newest first?
-t
How do we view all files except . and .. ones?
ls -A
how do we view more info about the files using ls?
-l
How do we sort by file size in ls?
-s
How do we know last time a file was accessed?q
-u
How do we know last time a file was modified using ls?
-l
How do we differentiate between absolute and relative paths?
absolute start with a “/” - slash! and relative ones start with a word.. :)
What does a recursive specifier do in copying folders and directories? also, what does a recursive specifier look like?
it’s an -R flag of the cp command
What’s the tag and commands for forced recursive removal?
rm -rf directoryname
How do we remove any file or folder that starts with a number
rm -rf [1-9]*
How do we remove any file or folder that END with .conf?
rm -rf *.conf
What’s the difference between ls -a and ls -A?
capital A shows almost everything (everything except the two dots), lower case shows everything everything!
How to view all the environment variables?
env
What is globbing?
Globbing is using partial matching to work with groups of files and directories. Matching patterns in fileframes or text by using a wildcard char to create a pattern
How do we look for a filename with four characters and a “1” at the end?
???1
What does a question mark do in globbing?
It matches any single character
What does an asterisk do in globbing?
Finds 0 to many matching characters. I.e. file* will match file, file1, file_kseirjnsfjkevn
What do brackets [] do?
They match character(s) from a range
How do we match uppercase characters with brackets? lowercase? digits?
[A-Z] [a-z] [1-9]
How do we customize which digits we want to match using brackets?
[2-5]
How do we say we want a character - of either case with brackets?
[a-zA-Z]
How do we say we want to match any alphanumeric character with brackets?
[a-zA-Z0-9]
How do we use caret in globbing?
We use it to match starting characters
How do we use dollar in globbing?
To match ending character
How do we use curly brace in globbing?
We match more than one pattern