week 7 Flashcards

(37 cards)

1
Q

Brace Expansions

A

Bash can fill in a pattern contained in braces
I.E echo {1 .. 10 .. 2}

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

command substitution

A

allows you to store the output of a command in a variable
ie list = $(ls)

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

arithmetic expansion

A

Evaluates a mathematical expression inside
ie $(( arithmetic ))

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

pattern matching: *

A

matches any sequence of characters

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

pattern matching: ?

A

matches any single character

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

pattern matching: []

A

matches any enclosed characters

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

Declaring function in Bash

A

function() {
body
}

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

How do you pass a argument into a bash function?

A

you must use positional parameters ie $1

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

Local variables

A

use the keyword ‘local’ behind what you want to be local scoped only
i.e. local users=$@

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

How do you return a value in a bash function?

A

Assign the value to a var and echo the var

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

Case

A

alternative to if/elif/else statements, allows you to patter match possible options and return something different depending
;; = end of condition
| = alternate condition
esac = end
i.e Case expression in:

A)
Echo A
;;
B)
echo B
;;
*)
echo everything
;;
esac

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

OPTARG

A

OPTARG contains the arguments used for each flag and is generally used in conjunction with while and case

while getopts “:a:b:” opt; do
case “${opt}” in
a) example=${OPTARG}
esac
done

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

shift

A

Shifts positional parameters n characters to the left, shift can stack with each other

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

what is YAML?

A

“YAML ain’t markup language”, a human readable, data serialization language

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

What command do you use to quit a process?

A

kill

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

what signal is sent by default when using the “kill” command?

17
Q

How do you send a different signal/SIGKILL with kill?

A

kill -9 or kill -SIGKILL

18
Q

How to show %mem with ps?

A

ps aux

option: add –sort=-%mem

19
Q

What is the signal code for sigint?

20
Q

what is the signal code for SIGKILL

21
Q

what is the signal code for SIGTERM

22
Q

How to find all lines that begin with a certain word? (regex)

A

grep “^GNU”

23
Q

how to find lines that end with a certain word? (regex)

A

grep “word$”

24
Q

What’s the difference between “.” and “?” in regex?

A

”?” matches for zero or more occurences while “.” matches any character

25
How to add user to a group>
sudo usermod –aG groupname username
25
How do you set password expiry?
sudo chage -M days username
26
how to change ownership of a file?
sudo chown username:group filename -R for recursive
27
Where would you find a list of groups?
/etc/group
28
command for creating a new group
groupadd
29
Where is the config file for nvim located?
/home/user/.config/nvim/init.lua
30
what does the shebang do?
tells the shell what interpreter to use
31
how to make variable accessible in subshell?
export $var
32
what would you use declare for?
1. creating an associative array (-A) 2. provide attributes to variables (-r for readme, NUM for int variable)
33
how to check if a file is older than another one using conditionals in scripting?
-ot
34
How to get all array items?
array[@]
35
how to get number of items in an array?
#array[@]
36
what's the difference between pkill and kill?
pkill allows you to kill a process via the process name while kill uses PID