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
What does this [/] indicate as a marker by a file?
A trailing [/] indicates that this is a directory.
26
What does this [@] indicate as a marker by a file?
Indicates a link
27
What does this [*] indicate as a marker by a file?
Indicates an executable
28
What are plain old files?
Any names in the output without a classification
29
What are sub-directories?
Directories under the main directories under the root
30
How to clean a cluttered terminal?
[clear] command
31
How to access previous commands?
Up and down to retrieve past lines
32
How to find out what options a command have and what it does?
[ —help]
33
What is the error for unsupported option?
ls: invalid option — ‘j’ Try ‘ls —help’ for more information
34
Another way to find out what options a command have and what it does?
[man ls]
35
What does [man ls] do differently?
Turns ur terminal into a page with a description of the command and its option.
36
How to search for something in the [man] page?
use [/] followed by the character or word you are searching for.
37
How to quit the [man] page?
Press [Q]
38
[ -l] option function
Long list format of the file and directory names With details like file size and last time or modification
39
[ -h] option function
Makes the file size/(numbers) human readable. 5.3K instead of 5369
40
In what order does [ls] list the contents?
Alphabetically
41
How does the [ -t] option for the ls command arrange the directory?
By the time it was last edited
42
How does the [ -r] option for the ls command arrange the directory?
Reverse order
43
How to get a listing of something other then our CWD? Name the parts.
[ls -F desktop] [ls] - lists stuff [ -F] - option [ Desktop] - argument
44
What does argument do as used in [ls -F Desktop]?
The argument [Desktop] sets a parameter. Tells [ls] that we want a listing of something other than our current working directory.
45
How to look at the contents of a sub-directory of non-cwd in ur cwd?
[ls -F argument/name of directory
46
Describe the cd progression?
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
47
How to go up a directory tree?
[cd . . ]
48
[cd . .] meaning?
Special directory meaning the directory containing this one. The parent of the cwd.
49
How to show the special [ . .] when u run [ls]?
add [ a] option to [ls -F]
50
What does the special directory [.] mean?
CWD
51
Purpose of the hidden [ .bash_profile]
For file configuration settings. Files and directories with the [.] prefix before them are to prevent the config files from cluttering the terminal.
52
How to go down 3 steps down the directory levels with one command line?
[cd directory name/sub/sub] This can go down for as long as there is a sub directory to access
53
How does the shell interprets the tilde ([~]) character?
Means the current user Cwd =/Users/user’s name/data
54
How does the shell interprets the tilde ([-]) character?
Translate into the previous directory u were in
55
[$ ls -F / ]
[$ ] - Prompt [ls] - Command [ -F] - Option [ /] - Argument
56
What is the functions of arguments?
Tell the command what to operate on (e.g files and directories)
57
Another name for arguments
Parameters
58
How many option and argument in a command?
Multiple
59
Do commands require always parameters?
No
60
Switch/flags
Options and mostly those that take no argument
61
What is the command sensitive about?
Case and Space sensitive
62
What does an absolute file specify?
A location from the root of the file system
63
What does a relative path specify?
Location starting from the current location
64
What is the command to make a directory?
[mkdir]
65
Why is [mkdir] a relative path?
Does not have a leading slash and def
66
[ -p] option, function
Allows [mkdir] to create a directory with nested subdirectories in a single operation.
67
[ -R] option, function
This option to the ls command will list all the nested sub directories within a directory
68
Why shouldn’t u use spaces when making directories and alternative?
Because they are used to make separate arguments use (-), (_) , and (.)
69
Should u begin a name with (-)?
No
70
How to refer to directories with special characters, spaces, etc
(“”)
71
What [nano] really means?
(Text) it can only work with plain character data. One of the least complex text editors
72
Explain the control key
Ctrl, ^, C
73
What does the [touch] command do and why use it?
The touch command generates a new file in your cwd. It’s can be used for programs that need help generating empty files.
74
What does the [rm] command do?
Removes a file
75
What are filename extension?
Second part of a file name that helps people and their programs tell the different kind of files apart
76
(.txt)
Signals a plain text file
77
(.pdf)
Indicates a PDF document
78
(.cfg)
Configuration file full of parameters for some programs or other.
79
(.png)
PNG image
80
What does the [mv] command do?
It moves files and directories but it can also rewrite them.
81
How to move a file or directory?
The first argument tells [mv] what we’re moving and the second where to go.
82
How to change file or directory name?
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
[ -i] or [ —interactive] option, function and purpose
[mv] will silently overwrite any existing file with the same name. This option makes it ask for permission
84
What does the [cp] command do?
It copies files
85
What does the recursive option [ -r] do?
It copy a directory and all its contents. You can use to backup a directory.
86
Dangers in using the [rm] command?
Deleting is forever use the [ -i] to be safe tho
87
How to remove directories and all their options?
[rm] itself can’t remove directores, adding the recursive [ -r] option will do that.
88
How to copy multiple files at once?
Put the files u want to copy with space in between them, the last argument has to be a directory name
89
What does [*] wildcard do?
Matches zero or more character in a filename
90
How to use [*]?
Use with ls command. [*] to replace missing character or characters
91
What does the [?] do?
Matches only one character.
92
How to use [?] wildcard?
Use [ls] then [?] To replace a missing word
93
[?] vs [*]
[*] 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
What does the (.pdb) extension indicates? Function?
That files are in Protein Data Bank format. A simple text format that the type and position of each atom in the molecule
95
What does the [wc] command stand for and what does it do?
Word count, it counts the number of line, words, and character (from left to right, in that order)
96
[wc -l], function
The output shows only the number of lines per file
97
[wc -m], function
Shows the number of characters
98
[wc -w], function
Show’s the number of words in the files
99
What happens when given a command to process a file but given no file name?
Sits there and waits for u to gives it data and appears to do nothing. Escape this state with ctrl + c
100
What does the [>] symbol tells the shell to do?
It tells the shell to redirect the command’s output to a file instead of printing it out.
101
When does the shell override a file?
When u tell it to create a file with a name that already exist
102
What does the [cat] command do? Where does it name come from?
It gets ur name from concaténate. It prints out contents of files one after the other
103
A more useful version of [cat]?
[less]
104
[less] function?
Displays a screenful of the file, and then stops.
105
How to operate the [less] command?
Go forward - spacebar Back one - b Q - quit
106
What does the [sort] command do?
Sorts alphanumerically
107
What does the [sort -n] do?
Sorts in a numerical order
108
What does the [head] command do?
To get the first few lines in the file. Needs the [ -n #] option tho # - sub for a number.
109
What does the command [head] do with [ -n 1] option? Another example?
Tells head we only want the first line. [ -n 20] would be the first 20 line
110
Why not redirect to the same file?
Might give incorrect result or delete the contents of the file
111
What does the [echo] command do?
The echo command prints text
112
How to write to files using the [echo] command?
Use the greater than sign [echo] (what ur writing) [>] or [>>] and then (name of the file ur writing to.
113
When using echo to write to files what’s the difference between [>] and [>>]?
[>] rewrites the entire file [>>] appends to the file
114
What does the [tail] command do?
Just like the [head] command the [tail] prints lines from the end of a file. Needs the [ -n #] option tho # - sub for a number.
115
What is a pipe? Purpose?
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
What is a filter?
A filter is a program like [wc] or [sort] that transforms a stream of input into a stream of output.
117
What is the purpose of the [cut] command? What does it expect?
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
What is a delimiter?
A character used to separate lines into columns.
119
What does the [ -d] do?
To specify what the delimiter is
120
Purpose of the [ -f] option?
To specify which row you wish to remove
121
How to isolate sections of a file with lines?
[cut -d (specify what separates ur columns) -f (which column u want out) (name of the file)]
122
What does the [uniq] command do?
Filters out adjacent matching lines in a file
123
What does the [uniq]’s command [ -c] option do?
Gives count to the number of times a line occurs in its input
124
Write the general loop form?
[For (thing) in (list_of_things) do (operation_using) $thing done] Indentation not needed but helps readability.
125
Prompts in loop, change purpose?
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
What does the [;] colon doing?
Used to separate two commands written on the same line.
127
What does the [$] in the general loop for do?
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
How to delimit variables?
Use the curly brackets. {} [$filename] = [${filename}] [${filename}] not = [${file}name]
129
Rules for variable?
Give them meaningful name
130
How to move to the beginning and end of the shell
Begin - [ Ctrl + A ] End - [Crtrl + E]
131
What is the [history] command?
Get a list of the last few hundred commands that have been executed
132
How to repeat a command after the [history] command?
[!(#)]
133
What does [!$] do?
Retrieves the last word of the last command.
134
What does the Ctrl + r shortcut do?
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
What is a dry run?
A cushion for mistakes. Use the [echo] command to show what a loop would do. Put the commands in double quotations.
136
Why give files consistent names?
Easy to match with wildcard pattern to make it easy to select them for looping.
137
What is a shell script?
A bunch of commands saved in a file is usually called a shell script. Small programs.
138
What does the [bash] command do?
Tells our file to execute the program
139
Why must one use plain text editor?
Shell tools only expect files to contain nothing but letters, number and special characters
140
What does [“$1”] means? Why put double quotes around it?
The first filename (or other argument) on the command line. In case it has spaces or confusing special characters add double quotes
141
What does [$2] and [$3] mean?
Second and third command line argument respectively
142
What is a comment? Purpose? Tip
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
What does the [$@] command mean? Purpose?
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
What happens when u use single quotations?
The shell does not expand the command to others and only does the command in the quote
145
What does the [ -x] option do?
It reruns the script. Runs in debug mode.
146
What does the [grep] command do?
Finds and prints lines in files that match a pattern.
147
How to use a [grep] command?
[grep (pattern) filename]
148
What does the [ -w] option does with the [grep] command?
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
What does the [ -n] option do for the [grep] command?
Gives u the line number for the lines that match.
150
What does the [ -i] option do for the [grep] command?
Makes the search case sensitive
151
What does the [ -v] option do for the [grep] command?
Inverts the search. Looks for line that does not contain the word(s)
152
What does the [ -r] (recursive) option do for the [grep] command?
Can search for a pattern recursively through a set files in subdirectories.
153
Where does [grep] real power come from?
Regular expressions. The ‘re’ in [grep].
154
Function of regular expressions
Both complex and powerful
155
When using [grep]’s regular expression whats the purpose of [ -E]?
To prevent the shell from trying to interpret the command. Not enough on its own
156
What does [“^.o”] do? Why?
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
What does the [find] command do?
Finds command files themselves
158
What does the [ -type d] option do for the [find] command?
It lists the directories including the cwd with no particular order
159
What does the [ -type f] option do for the [find] command?
List the files with no particular order
160
What does the [ -name] option do for the [find] command?
Can find all the files that contain the letters given and if there are missing letters use [*] as subs
161
What does the [$()] command do
The shell executes this first then replace it with its output