Command Line Flashcards

1
Q

What if the UNIX Shell?

A

Both a command-line interface (CLI) and a scripting language

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

What is the function of the UNIX shell

A

A better GUI alternative that allows repetible tasks to be done automatically and fast. Tasks that takes the GUI hours will take the shell seconds.

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

What is the shell?

A

A program where users can type commands ranging from complicated climate modeling software to simple file creations

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

What is the most popular UNIX Shell

A

Bash (Bourne Again Shell)

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

What are scripts? Purpose?

A

Sequences of commands written using the grammar of a shell to improve the reproducibility of workflows.

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

Examples of the shell abilities?

A

Can be used to interact with remote machine and super computers. It can also be used to tackle scientific questions and computational challenges.

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

What is $? What to do and not?

A

This is the shell’s prompt typically. Do not type the prompt, only the commands after it. Press enter to execute it.

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

What is the [ls] command and what does it mean?

A

[ls] - short for listing. This lists the contents of the current directory

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

What happens when shells can’t find ur command?

A

$ (command): command not found

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

What are the shells main disadvantages?

A

The shell’s main disadvantages are its primarily textual nature and how cryptic its command and operations can be.

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

What is the file system?

A

The part of the OS responsible for managing files and directories.

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

Current working directory

A

Directories are like places. At any time we r using the shell we are exactly in one this.

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

Why knowing ur current working directory is important?

A

Command mostly read and write files in the current working directory

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

What is the [pwd] command?

A

Shows you where you are

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

What is the [cd] command?

A

Navigates you to ur home directory

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

[/]

A

Root directory that hold everything else it’s the leading slash in ur home directory

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

What other directories are inside the root directory?

A

[bin], [data], [Users], and [tmp] etc.

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

Function of the [bin]

A

This is where some built-in programs are stored.

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

Functions of [data]

A

(For miscellaneous data files)

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

Functions of the [Users] directories

A

It’s where the user’s personal directories are located.

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

Functions of the [tmp] directory ?

A

For temporary files that don’t need to be stored longterm

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

The seconding meaning of the slash?

A

When it appears inside a path, it’s just a separator

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

Where are user Imhotep files stored in?

A

They are stored in all user’s directory

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

[ -F] option

A

Tells [ls] to classify the output by adding a marker to file and directory names to indicate what they are.

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

What does this [/] indicate as a marker by a file?

A

A trailing [/] indicates that this is a directory.

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

What does this [@] indicate as a marker by a file?

A

Indicates a link

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

What does this [*] indicate as a marker by a file?

A

Indicates an executable

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

What are plain old files?

A

Any names in the output without a classification

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

What are sub-directories?

A

Directories under the main directories under the root

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

How to clean a cluttered terminal?

A

[clear] command

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

How to access previous commands?

A

Up and down to retrieve past lines

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

How to find out what options a command have and what it does?

A

[ —help]

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

What is the error for unsupported option?

A

ls: invalid option — ‘j’
Try ‘ls —help’ for more information

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

Another way to find out what options a command have and what it does?

A

[man ls]

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

What does [man ls] do differently?

A

Turns ur terminal into a page with a description of the command and its option.

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

How to search for something in the [man] page?

A

use [/] followed by the character or word you are searching for.

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

How to quit the [man] page?

A

Press [Q]

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

[ -l] option function

A

Long list format of the file and directory names
With details like file size and last time or modification

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

[ -h] option function

A

Makes the file size/(numbers) human readable. 5.3K instead of 5369

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

In what order does [ls] list the contents?

A

Alphabetically

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

How does the [ -t] option for the ls command arrange the directory?

A

By the time it was last edited

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

How does the [ -r] option for the ls command arrange the directory?

A

Reverse order

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

How to get a listing of something other then our CWD? Name the parts.

A

[ls -F desktop]

[ls] - lists stuff
[ -F] - option
[ Desktop] - argument

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

What does argument do as used in [ls -F Desktop]?

A

The argument [Desktop] sets a parameter. Tells [ls] that we want a listing of something other than our current working directory.

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

How to look at the contents of a sub-directory of non-cwd in ur cwd?

A

[ls -F argument/name of directory

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

Describe the cd progression?

A

To change the shells cwd u use [cd]
You can only go down into the directory tree within the cwd or to the home directory

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

How to go up a directory tree?

A

[cd . . ]

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

[cd . .] meaning?

A

Special directory meaning the directory containing this one. The parent of the cwd.

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

How to show the special [ . .] when u run [ls]?

A

add [ a] option to [ls -F]

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

What does the special directory [.] mean?

A

CWD

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

Purpose of the hidden [ .bash_profile]

A

For file configuration settings. Files and directories with the [.] prefix before them are to prevent the config files from cluttering the terminal.

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

How to go down 3 steps down the directory levels with one command line?

A

[cd directory name/sub/sub]
This can go down for as long as there is a sub directory to access

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

How does the shell interprets the tilde ([~]) character?

A

Means the current user Cwd
=/Users/user’s name/data

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

How does the shell interprets the tilde ([-]) character?

A

Translate into the previous directory u were in

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

[$ ls -F / ]

A

[$ ] - Prompt
[ls] - Command
[ -F] - Option
[ /] - Argument

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

What is the functions of arguments?

A

Tell the command what to operate on (e.g files and directories)

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

Another name for arguments

A

Parameters

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

How many option and argument in a command?

A

Multiple

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

Do commands require always parameters?

A

No

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

Switch/flags

A

Options and mostly those that take no argument

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

What is the command sensitive about?

A

Case and Space sensitive

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

What does an absolute file specify?

A

A location from the root of the file system

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

What does a relative path specify?

A

Location starting from the current location

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

What is the command to make a directory?

A

[mkdir]

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

Why is [mkdir] a relative path?

A

Does not have a leading slash and def

66
Q

[ -p] option, function

A

Allows [mkdir] to create a directory with nested subdirectories in a single operation.

67
Q

[ -R] option, function

A

This option to the ls command will list all the nested sub directories within a directory

68
Q

Why shouldn’t u use spaces when making directories and alternative?

A

Because they are used to make separate arguments use (-), (_) , and (.)

69
Q

Should u begin a name with (-)?

A

No

70
Q

How to refer to directories with special characters, spaces, etc

A

(“”)

71
Q

What [nano] really means?

A

(Text) it can only work with plain character data. One of the least complex text editors

72
Q

Explain the control key

A

Ctrl, ^, C

73
Q

What does the [touch] command do and why use it?

A

The touch command generates a new file in your cwd. It’s can be used for programs that need help generating empty files.

74
Q

What does the [rm] command do?

A

Removes a file

75
Q

What are filename extension?

A

Second part of a file name that helps people and their programs tell the different kind of files apart

76
Q

(.txt)

A

Signals a plain text file

77
Q

(.pdf)

A

Indicates a PDF document

78
Q

(.cfg)

A

Configuration file full of parameters for some programs or other.

79
Q

(.png)

A

PNG image

80
Q

What does the [mv] command do?

A

It moves files and directories but it can also rewrite them.

81
Q

How to move a file or directory?

A

The first argument tells [mv] what we’re moving and the second where to go.

82
Q

How to change file or directory name?

A

The first argument after [mv] will be the path or file name to the ur the file u want to change in the cwd and the second will be the path or file name that will override it

83
Q

[ -i] or [ —interactive] option, function and purpose

A

[mv] will silently overwrite any existing file with the same name. This option makes it ask for permission

84
Q

What does the [cp] command do?

A

It copies files

85
Q

What does the recursive option [ -r] do?

A

It copy a directory and all its contents. You can use to backup a directory.

86
Q

Dangers in using the [rm] command?

A

Deleting is forever use the [ -i] to be safe tho

87
Q

How to remove directories and all their options?

A

[rm] itself can’t remove directores, adding the recursive [ -r] option will do that.

88
Q

How to copy multiple files at once?

A

Put the files u want to copy with space in between them, the last argument has to be a directory name

89
Q

What does [*] wildcard do?

A

Matches zero or more character in a filename

90
Q

How to use [*]?

A

Use with ls command. [*] to replace missing character or characters

91
Q

What does the [?] do?

A

Matches only one character.

92
Q

How to use [?] wildcard?

A

Use [ls] then [?] To replace a missing word

93
Q

[?] vs [*]

A

[] Gives u the file(s) that contain ur looking for and any other that matches it . Kind of a substitute for all the words that might be after the []

[?] Gives u the file(s) that contain the words behind the [?]. Kind of a substitute for one word that might be after the [?]

94
Q

What does the (.pdb) extension indicates? Function?

A

That files are in Protein Data Bank format. A simple text format that the type and position of each atom in the molecule

95
Q

What does the [wc] command stand for and what does it do?

A

Word count, it counts the number of line, words, and character (from left to right, in that order)

96
Q

[wc -l], function

A

The output shows only the number of lines per file

97
Q

[wc -m], function

A

Shows the number of characters

98
Q

[wc -w], function

A

Show’s the number of words in the files

99
Q

What happens when given a command to process a file but given no file name?

A

Sits there and waits for u to gives it data and appears to do nothing. Escape this state with ctrl + c

100
Q

What does the [>] symbol tells the shell to do?

A

It tells the shell to redirect the command’s output to a file instead of printing it out.

101
Q

When does the shell override a file?

A

When u tell it to create a file with a name that already exist

102
Q

What does the [cat] command do? Where does it name come from?

A

It gets ur name from concaténate. It prints out contents of files one after the other

103
Q

A more useful version of [cat]?

A

[less]

104
Q

[less] function?

A

Displays a screenful of the file, and then stops.

105
Q

How to operate the [less] command?

A

Go forward - spacebar
Back one - b
Q - quit

106
Q

What does the [sort] command do?

A

Sorts alphanumerically

107
Q

What does the [sort -n] do?

A

Sorts in a numerical order

108
Q

What does the [head] command do?

A

To get the first few lines in the file.

Needs the [ -n #] option tho
# - sub for a number.

109
Q

What does the command [head] do with [ -n 1] option? Another example?

A

Tells head we only want the first line. [ -n 20] would be the first 20 line

110
Q

Why not redirect to the same file?

A

Might give incorrect result or delete the contents of the file

111
Q

What does the [echo] command do?

A

The echo command prints text

112
Q

How to write to files using the [echo] command?

A

Use the greater than sign [echo] (what ur writing) [>] or [»] and then (name of the file ur writing to.

113
Q

When using echo to write to files what’s the difference between [>] and [»]?

A

[>] rewrites the entire file
[»] appends to the file

114
Q

What does the [tail] command do?

A

- sub for a number.

Just like the [head] command the [tail] prints lines from the end of a file. Needs the [ -n #] option tho

115
Q

What is a pipe? Purpose?

A

This is the vertical bar [|]. Put between two commands. It tells the shell we want to use the output of the command on the left as the input of the command on the right

116
Q

What is a filter?

A

A filter is a program like [wc] or [sort] that transforms a stream of input into a stream of output.

117
Q

What is the purpose of the [cut] command? What does it expect?

A

It’s to remove certain sections of each line in the file and [cut] expects the lines to be separated into columns by a (Tab) character.

118
Q

What is a delimiter?

A

A character used to separate lines into columns.

119
Q

What does the [ -d] do?

A

To specify what the delimiter is

120
Q

Purpose of the [ -f] option?

A

To specify which row you wish to remove

121
Q

How to isolate sections of a file with lines?

A

[cut -d (specify what separates ur columns) -f (which column u want out) (name of the file)]

122
Q

What does the [uniq] command do?

A

Filters out adjacent matching lines in a file

123
Q

What does the [uniq]’s command [ -c] option do?

A

Gives count to the number of times a line occurs in its input

124
Q

Write the general loop form?

A

[For (thing) in (list_of_things)
do
(operation_using) $thing
done]

Indentation not needed but helps readability.

125
Q

Prompts in loop, change purpose?

A

The shell prompt changes from [$] to [>] and back again as we type the loop. The [>] prompt is to remind us we haven’t finish typing a complete command.

126
Q

What does the [;] colon doing?

A

Used to separate two commands written on the same line.

127
Q

What does the [$] in the general loop for do?

A

Calls for the variable’s value by putting [$] in front of it. Tells the shell interpreter to treat the variable as a variable name and substitute it’s value in its place, rather than treat it as text or an external command.

128
Q

How to delimit variables?

A

Use the curly brackets. {}
[$filename] = [${filename}]

[${filename}] not = [${file}name]

129
Q

Rules for variable?

A

Give them meaningful name

130
Q

How to move to the beginning and end of the shell

A

Begin - [ Ctrl + A ]
End - [Crtrl + E]

131
Q

What is the [history] command?

A

Get a list of the last few hundred commands that have been executed

132
Q

How to repeat a command after the [history] command?

A

[!(#)]

133
Q

What does [!$] do?

A

Retrieves the last word of the last command.

134
Q

What does the Ctrl + r shortcut do?

A

Entera a history search mode ‘reverse-i-search’ and finds the most recent command in your history that matches the text you enter next.

135
Q

What is a dry run?

A

A cushion for mistakes. Use the [echo] command to show what a loop would do. Put the commands in double quotations.

136
Q

Why give files consistent names?

A

Easy to match with wildcard pattern to make it easy to select them for looping.

137
Q

What is a shell script?

A

A bunch of commands saved in a file is usually called a shell script. Small programs.

138
Q

What does the [bash] command do?

A

Tells our file to execute the program

139
Q

Why must one use plain text editor?

A

Shell tools only expect files to contain nothing but letters, number and special characters

140
Q

What does [“$1”] means? Why put double quotes around it?

A

The first filename (or other argument) on the command line. In case it has spaces or confusing special characters add double quotes

141
Q

What does [$2] and [$3] mean?

A

Second and third command line argument respectively

142
Q

What is a comment? Purpose? Tip

A

A comment starts with a [#] character and runs to the end of the line. The computer ignores them but people use them to understand your code. Each time u modify ur script check if the comment is still accurate.

143
Q

What does the [$@] command mean? Purpose?

A

All the command-line argument to the shell scripts. Equivalent to [“$1” “$2” …]
Add quotations. Use to manipulate all sort of files including those in other directories.

144
Q

What happens when u use single quotations?

A

The shell does not expand the command to others and only does the command in the quote

145
Q

What does the [ -x] option do?

A

It reruns the script. Runs in debug mode.

146
Q

What does the [grep] command do?

A

Finds and prints lines in files that match a pattern.

147
Q

How to use a [grep] command?

A

[grep (pattern) filename]

148
Q

What does the [ -w] option does with the [grep] command?

A

It restricts matches to line containing the word on its own. Word boundaries. This also applies to multiple words and spaces. Quotes is useful for multiple words

149
Q

What does the [ -n] option do for the [grep] command?

A

Gives u the line number for the lines that match.

150
Q

What does the [ -i] option do for the [grep] command?

A

Makes the search case sensitive

151
Q

What does the [ -v] option do for the [grep] command?

A

Inverts the search. Looks for line that does not contain the word(s)

152
Q

What does the [ -r] (recursive) option do for the [grep] command?

A

Can search for a pattern recursively through a set files in subdirectories.

153
Q

Where does [grep] real power come from?

A

Regular expressions. The ‘re’ in [grep].

154
Q

Function of regular expressions

A

Both complex and powerful

155
Q

When using [grep]’s regular expression whats the purpose of [ -E]?

A

To prevent the shell from trying to interpret the command. Not enough on its own

156
Q

What does [“^.o”] do? Why?

A

If [*] is used without quotes the shell would try to expand it.
^ - is the pattern anchors the match to the start of the line
. - Matches a single character
o - matches an actual o

157
Q

What does the [find] command do?

A

Finds command files themselves

158
Q

What does the [ -type d] option do for the [find] command?

A

It lists the directories including the cwd with no particular order

159
Q

What does the [ -type f] option do for the [find] command?

A

List the files with no particular order

160
Q

What does the [ -name] option do for the [find] command?

A

Can find all the files that contain the letters given and if there are missing letters use [*] as subs

161
Q

What does the [$()] command do

A

The shell executes this first then replace it with its output