Chapter 1: Exploring Linux Command-Line Tools Flashcards

1
Q

shell

A

A program that interprets text commands and provides an interface to the system, e.g. bash in terminal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Environment Variables

A

Placeholders for for data that may be useful to many programs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

bash

A

Most common default shell

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

sh

A

The original Bourne shell which bash is based off of, and not often used

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

tcsh

A

Based on the C shell (csh), fairly popular

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

ksh

A

The Korn shell, designed to combine the best features of sh and csh

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

zsh

A

Tries to extend ksh

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Default Interactive Shell

A

The shell a user uses to enter commands, run run programs, run shell scripts, etc., from command line.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Default System Shell

A

Used to run system shell scripts, typically at startup

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

/bin/sh

A

A file that points to the system’s default system shell (normally bin/bash)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

uname -a

A

Shows the operating system being run, along with hostname and kernel version

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Built-In Commands

A

Commands built into the shell program, AKA internal commands

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

time

A

Command that tells you how long commands take to execute, e.g. time pwd tells you how long pwd takes to execute

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

set

A

Displays options relating to bash shell operation.

Can also change options if specified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

exit and logout

A

exit terminates any shell, and logout terminates only login shells

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

type ____

A

Checks if a command is internal or external

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

type -a ____

A

Same as type, but checks to see if there are both internal and external versions of the command

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

path

A

A list of directories in which commands can be found

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

How to Search for a Previously Done Command

A

Ctrl+R then type what you’re looking for.

Ctrl+S to search forward if you pass what you were looking for

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

If Ctrl+S not working when searching for a command, what command should you use to fix it?

A

stty -ixon

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How to exit searching for a command?

A

Ctrl+G

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How to move to beginning of line?

A

Ctrl+A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

How to move to end of line?

A

Ctrl+E

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How to move through a line one word at a time?

A

Ctrl+Left or Right Arrow

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Backspace vs. Delete
Backspace deletes the character to the left of the cursor, while Delete deletes the character under the cursor
26
How to delete all text from cursor to the end of the line?
Ctrl+K
27
How to delete all text from cursor to beginning of the line?
Ctrl+X then Backspace
28
How to transpose letters or words?
Ctrl+T
29
How to change a word to uppercase? lowercase?
Esc then U Esc then L
30
How to change a single letter to uppercase?
Esc then C
31
How to bring up an editor of the command on the line?
Ctrl+X then Ctrl+E
32
How to retrieve the last command and execute it?
!!
33
How to clear the command history?
history -c
34
How to execute a command by number?
! followed by the number
35
What is the name of the file where command history is stored?
.bash_history
36
What does an environment variable look like?
$VAR
37
How to view all environment variables?
env
38
How to delete an environment variable?
unset
39
How to search man pages?
man -k along with your keyword in quotes
40
whatis database
Contains a short description of each man page
41
How to create or update the whatis database?
makewhatis
42
man section 1
Executable programs and shells
43
man section 2
System calls provided by the kernel
44
man section 3
Library calls provided by program libraries
45
man section 4
Device Files
46
man section 5
File formats
47
man section 6
Games
48
man section 7
Miscellaneous
49
man section 8
System administration commands
50
man section 9
Kernel routines
51
An alternative to man
info
52
What are the pages about the built in commands called?
help pages
53
Stream
A data entity that can be manipulated
54
>
Creates a new file containing STDOUT
55
>>
Appends STDOUT to an existing file
56
2>
Creates a new file containing STDERR
57
2>>
Appends STDERR to the existing file
58
&>
Creates a new file containing STDOUT and STDERR
59
Sends the contents of the specified file to be used at STDIN
60
Accepts text on the following lines as STDIN
61
Causes the specified file to be used as both STDIN and STDOUT
62
What is the file you redirect output to if you want to get rid of it?
/dev/null
63
here document
Takes text from subsequent lines as standard input
64
How do you indicate that you are done with typing input when you use the
EOF
65
| (pipe)
Redirects the first program's standard output to the second programs standard input
66
tee
Splits STDIN so that it's displayed on STDOUT and in as many files as you specify. Often used with pipes
67
xargs
Builds a command from it's standard input. xargs [options] [command [initial arguments]]
68
What do you surround a command with if you want it to be treated as a separate command from the rest of the line?
Either ` or $()
69
cat
Links together an arbitrary number of files end to end and sends the result to STDOUT
70
How to show end of lines when using cat?
cat -E
71
How to number the lines when using cat?
cat -n numbers all lines cat -b numbers only the lines that have text
72
How to compress blank lines when using cat?
cat -s | Makes multiple blank lines into a single blank line
73
cat -T
Displays tab characters as ^I
74
cat -v
Displays special characters using carat (^) and M- notations
75
tac
Like cat, but reverses the order of the lines
76
join
Combines two files by matching the contents of specified fields. Fields are typically space-separated
77
How to specify a different separator for the fields when using join?
join -t [char you want]
78
How to make join case-insensitive?
join -i
79
How to specify the fields you want to join?
join -1 [num] -2 [num]
80
paste
Merges files line by line, separating the lines from each file by a tab
81
What is the command that converts tabs to spaces?
expand
82
od
Displays a file in octal
83
sort
Used to sort files
84
sort -f
Causes sort to ignore case
85
sort -M
Sorts by three letter month abbreviations
86
sort -n
Sort by number
87
sort -r
Sort in reverse
88
How do you sort by a specific field with sort?
sort -k [number of the field you want to use]
89
split
Splits a file into two or more files
90
split -b [size]
Splits a file into the specified size of bytes
91
split -l [num]
splits the file by the number of lines specified
92
How do you signal EOF with a keystroke?
Ctrl+D
93
tr [options] [set1] [set2]
each character in set 1 is replaced by the corresponding element of set 2
94
tr -d
Deletes the characters specified in set1, and set 2 is omitted
95
tr -t
Makes set 1 the same size as set 2 if they are different sizes
96
unexpand
Converts multiple spaces to tabs
97
uniq
Removes duplicate lines.
98
fmt
Tries to format a file well. | Makes lines no longer than 75 characters by default
99
fmt -w [num]
Allows you to set the desired length of the lines
100
nl
Command used to number lines
101
nl -b [style]
Specifies the body numbering style
102
nl -h [style]
Specifies the header numbering style
103
nl -f [style]
Specifies the footer numbering style
104
nl -d=[code]
Tells it that a new page starts wherever it sees what you specify as the code
105
nl -p
Tells it to not start renumbering when it reaches a new page
106
nl -n [format]
Specifies the numbering format: 1) ln (left justified, no leading zeroes) 2) rn (right justified, no leading zeroes) 3) rz (right justified, with leading zeroes)
107
Styles if numbering for nl
1) t: number the lines that aren't empty only 2) a: number all lines 3) n: omits all line numbers 4) p[REGEX]: only lines that match the REGEX are numbered
108
pr [file]
- Puts the file into a format for printing. - 80 character line lengths - Includes the original text with headers, which list the current date and time, the original filename, and the page number.
109
How to make pr use a certain number of columns?
pr -[num] or pr --columns=[num]
110
How to make pr use double spacing?
pr -d or pr --double-space
111
How to make pr form-feed between pages?
``` pr -f or pr -F or pr --form-feed ```
112
How to set the page length for pr?
pr -l [num] or pr --length=[num]
113
How to set the text to be displayed in the header using pr?
pr -h [text] or pr --header=[text]
114
How to change the left margin for pr?
pr -o [num] or pr --indent=[num]
115
How to set the page width for pr? Also, what is the default width?
pr -w [num] or pr -width [num] 72
116
head [file(s)]
Shows you the first 10 lines of one or more files
117
How to specify the number of bytes you want to view for head?
head -c [num] or head --bytes=[num]
118
How to specify the number of lines you want to view for head?
head -n [num] or head --lines=[num]
119
tail [file(s)]
Displays the last 10 lines of one or more files. | Options are the same as head for specifying bytes or lines desired.
120
How to keep a file open and see when lines are added to it for tail?
tail -f or tail --follow
121
How to tell tail to stop tracking once a certain process ends?
tail -pid=[process ID]
122
How to move forward a screen when using less?
spacebar
123
How to move backward a screen when using less?
Esc then V
124
How to search forward in a file while using less?
/ followed by the search term
125
How to move to the next occurrence of a searched term in less? previous?
n N
126
How to search backward in a file while using less?
? then the search term
127
How to move to a specific line while using less?
g followed by the number of the line
128
How to view help while in less?
h
129
cut
Extracts portions of input lines and displays them on STDOUT
130
How to specify the list of bytes to cut using cut?
cut -b [list] or cut --bytes=[list]
131
How to specify characters to be cut using cut?
cut -c [list] or cut --characters=[list]
132
How to use cut by field?
cut -f [list] or cut --fields=[list]
133
How to set the delimiting character when using cut?
``` cut -d [char] or cut --delim=[char] or --delimiter=[char] ```
134
wc [file]
Produces a word count of a file, as well aslines and bytes
135
How to limit the output of wc to line count? word count? byte count? character count? max line-length?
--lines or -l --words or -w --bytes or -c --chars or -m --max-line-length or -L
136
Regular Expression
A tool for describing or matching patterns in text
137
What would be matched using the regular expression b[eia]g
beg, big, and bag
138
What would be matched using the regular expression a[2-4]z
a2z, a3z, a4z
139
What would be matched using the regular expression a.z
Any three character string beginning with a and ending with z
140
Which symbol represents the beginning of a line in regular expressions? the end of a line?
^ $
141
What does the * repetition operator indicate?
Zero or more occurrences
142
What does the + repetition operator indicate?
One or more occurrences
143
What does the ? repetition operator indicate?
Zero or one occurrence
144
What would be matched to the regular expression car|truck
car or truck
145
What are parentheses used for in regular expressions?
Used to group subexpressions
146
grep [options] [regex] [files]
Searches for files that contain a specified string
147
How to count the number of lines that match for grep?
grep -c or grep --count
148
How to specify a pattern input file for grep?
grep -f [file] or grep --file=[file]
149
How to make grep case-insensitive?
grep -i or grep --ignore-case
150
How to search in specified directory and all subdirectories with grep?
``` grep -r or grep --recursive or rgrep ```
151
How to make grep not recognize characters as regular expression characters and instead take them literally?
``` grep -F or grep --fixed-strings or fgrep ```
152
How to use extended regular expressions with grep?
``` grep -e or grep --extended-regexp or egrep ```
153
sed [options] -f [script-file] [input-file] or sed [options] [script-text] [input-file]
- Modifies input-file using a set of commands specified in script-text or script-file, and sends it to STDOUT. - Typically you should surround script-text in single quotes.
154
sed command =
Displays the current line number
155
sed command a\"text"
Append "text" to the file
156
sed command i\"text"
Insert "text" into the file
157
sed command r "filename"
Append text from "filename" into the file
158
sed command c\"text"
Replace the selected range of lines with the provided text
159
sed command s/"regexp"/"replacement"
Replace text that matches "regexp" with "replacement"
160
sed command w "filename"
Write the current pattern space to the specified file
161
sed command q
Immediately quit the script, but print the current pattern space
162
sed command Q
Immediately quit the script.
163
What is a special purpose program that can convert a DOS-style file to a Unix-style file?
dos2unix