week 7 Flashcards

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

echo what you want to return and assign the return to a new variable

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?

A

SIGTERM

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?

A

2

20
Q

what is the signal code for SIGKILL

A

9

21
Q

what is the signal code for SIGTERM

A

15

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
Q

How to add user to a group>

A

sudo usermod –aG groupname username

25
Q

How do you set password expiry?

A

sudo chage -M days username

26
Q

how to change ownership of a file?

A

sudo chown username:group filename

-R for recursive

27
Q

Where would you find a list of groups?

A

/etc/group

28
Q

command for creating a new group

A

groupadd

29
Q

Where is the config file for nvim located?

A

/home/user/.config/nvim/init.lua

30
Q

what does the shebang do?

A

tells the shell what interpreter to use

31
Q

how to make variable accessible in subshell?

A

export $var

32
Q

what would you use declare for?

A
  1. creating an associative array (-A)
  2. provide attributes to variables (-r for readme, NUM for int variable)
33
Q

how to check if a file is older than another one using conditionals in scripting?

A

-ot

34
Q

How to get all array items?

A

array[@]

35
Q

how to get number of items in an array?

A

array[@]

36
Q

what’s the difference between pkill and kill?

A

pkill allows you to kill a process vi