Shell and Command Line Basics Flashcards
internal command
command within your shell, part of the shell
external command
stored as separate binaries, started with a sub-process
PATH
environment variable storing a list of directories in which commands can be found
change PATH variable by editing…
shell config file
required to run programs which don’t exist in PATH
complete path of the utility
command completion
type part of a command or filename and press Tab key for completion
- displays result or possible results
history
- record of typed commands
- stored in /bash_history
- up and down arrow keys
historical search
- ctrl+R to begin a reverse search
- ctrl+S is a forward search
- ctrl+G terminate search
movement
- ctrl+A start of line
- ctrl+E end of line
- ctrl+left or right arrows move by one word
delete text
- ctrl+D or delete key deletes character under cursor
- backspace deletes character to the left of cursor
- ctrl+K deletes all text from cursor to end of line
- ctrl+X, backspace deletes all text from cursor to start of line
invoke an editor
- ctrl-X, ctrl+E
- launches an editor defined by FCEDIT or EDITOR environment variables
main global config files for shell
- ~/.bashrc
- ~/.profile
~ directory
your home directory
environment variables
value references which can be shared by different programs within an environment
set environment variable
- know name of env var
- use assignment operator (=)
- export variable
(i. e. export NNTPSERVER=new.abigisp.com)
$ identifier
identifies a variable (i.e. echo $PATH)
command env
view entire environment of variables
command unset
- remove environment variable
- syntax: unset [variableName]
command man
- text-based system known as man, for manual
- syntax: man [programName]
less pager
- displays information
- spacebar to move forward by a page
- esc followed by V to move back a page
- arrow keys move up or down line by line
- / key to search for text
- q key to exit
command info
- info pages which allow hypertext format
- syntax: info [program]
stream
data entity that can be manipulated
standard input stream
stdin input typically from a keyboard
standard output stream
stdout, normally displayed on screen
standard error stream
- stderr, carry high-priority info such as error messages
- typically sent to stdout
> redirection
creates a new file containing stdout, overwriting if necessary
> > redirection
appends stdout to existing file, creating if necessary
2> redirection
creates a new file containing stderr, overwriting if necessary
2» redirection
appends stderr to existing file, creating if necessary
&> redirection
creates a new file containing both stdout and stderr, overwriting if necessary
< redirection
sends contents of file as stdin
«_space;redirection
accepts text on following lines as stdin
<> redirection
causes specified file to be used for both stdin and stdout
stdin number
0
stdout number
1
sterr number
2
null device
/dev/null
potentially usable to discard data
tee
splits stdin to diplay on stdout and as many files as specified
operator
pipe
piping
redirecting output from one program to the input of another program
command cat
- concatenate files linking them together end to end into one file
- typing one file will simply display that file in stdout
command expand
convert tabs to spaces
fmt command
reformat paragraphs
command head
view beginning lines of a file
command od
display files in Octal
command od
display files in octal (base-8)
command sort
sort files
command split
break a file into pieces
command tr
- translate characters
- syntax: tr [options] set1 set2
command uniq
delete duplicate lines
command nl
number lines
command pr
prepare a plain-text file for printing
comman tail
diplays lines at end of file
command less
- read a file a screen at a time, paging back and forth through the file
- spacebar pages forward
- escape+V goes back a page
command cut
extract portions of input lines and displat them on stdout
command cut
extract portions of input lines and display them on stdout
command wc
- displays word count as well as line and byte counts for a file
- syntax: wc [fileName]
regular expressions
express patterns in text
[] regex
match any one character within brackets
range regex
variant of bracket, matches any character within a range with a start and end point
dot regex
matches any character
^ regex
matches the start of a line
$ regex
matches the end of a line
- regex
matches zero or more occurrences
+ regex
matches one or more occurrences
regex
vertical bar matches multiple possibilities (i.e. car|truck)
() regex
denote subsection, think order of operations
\ regex
escapes following character, literally matching the following character regardless if it is a special character
command grep
- search through output
- syntax: grep [options] regexp [files]
command sed
- modifying text
- syntax: sed [options] -f script-file [input-file] sed [options] script-text [input-file]
- script text is the set of commands sed should perform