midterm Flashcards

1
Q

Which directory is passwd in?
What kinds of information does the passwd file store?

A

/etc/passwd

Store stuff like:
username, password (x if it’s encrypted), UID, GID, location of home directory, location of login shell

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

Where is encrypted password stored?

A

/etc/shadow

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

Is it possible to read /etc/passwd file as a regular user?

A

Yes

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

What type of info does /etc/shadow have?

A
  • username
  • encrypted password
  • last password change
  • min/max password age
  • warning period
  • inactivity period
  • expiration date
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How to add a new user?

A

useradd

useradd [options] username

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

Where is default configuration for useradd?

A

/etc/default/useradd

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

how to delete a user?

A

userdel
userdel -r username (if you want to remove their home directory too)

userdel [options] username

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

Why might you not be able to delete a user?

A

User still have running processes. Kill processes under a user by:

pkill -u username

or you can forcefully delete user with:
userdel -fr username

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

How to ser password for a new user?

A

passwd username

Will prompt you to enter password twice. Nothing will be showed on the screen though

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

How to lock and unlock a user account?

A

sudo passwd -l username (for lock)
sudo passwd -u username (for unlock)

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

how to view groups a member is in?

A

groups username

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

how to create a new group?

A

groupadd

groupadd [options] group-name

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

which folder has info about groups on your system?

A

/etc/group

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

what does the sudo command do?

A

allows a user to temporarily perform tasks with elevated privileges

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

where are the configurations for sudo?

A

/etc/sudo.conf

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

where are the configurations for who can use sudo?

A

/etc/sudoers

a sudoers file will generally include a line that grants members of their the “sudo” group or “wheel” group sudo privileges. eg. %wheel ALL+(ALL) ALL

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

what directory contains individual configuration files?

A

/etc/sudoers.d/

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

Why do we have sudo command? why not use root for everything/

A

Always want to give least privileges as possible so they can’t do what they shouldn’t do.

Accountability

Security. There’s add security for what hackers have to guess.

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

who to add user to a group?

A

sudo usermod -aG group user

the “a” is for append. Will not overwrite other groups the user is in.

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

What are the permissions?

A

r = read
w = write
x = execute
- = placeholder for permissions user does not have

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

format of what permissions looks like?

A

d rwx rw- r–

d = directory (file type)
then user permission
then group
then other

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

What are the octal/numeric permissions?

A

4 = read
2 = write
1 = execute

eg.
chmod 644 filename
(still in user, group, other order)

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

how to change file ownership?

A

chown

chown [options] user:group file

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

how to set password expiry?

A

sudo usermod -e YYY-MM-DD user

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

How to provide an enivornment similar to what the user would have if they had logged in directly?

A

su -l username

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

how many groups can a file belong to?

A

1

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

can a user belong to more than one group?

A

yes

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

What’s a file descriptor?

A

unique, positive number used to identify a open file. When process makes successful request to open a file, the kernel returns the file descriptor. File descriptor points to file table, which has info about file permissions

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

how to view file descript?

A

ls -l /proc/<pid>/fd

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

what are the 3 default file descriptors?

A

stdin (0) - defaults to input from keyboard, can be from tther files too
stdout (1) - defaults to user’s screen
stderr (2) - defaults to user’s screen

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

What’s the “redirect standard out”?

A

> (clobber, will overwrite)
> (append, add it to the end)

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

What’s the “redirect standard error”?

A

2>

eg.
find /etc -type f 2> errors
(redirects it to a file called errors)

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

what’s the special file that doesn’t store information sent to it?

A

/dev/null

eg.
command 2> /dev/null

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

how to combine standard out and standard error?

A

&>

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

How to user stdin where input comes from a file instead of keyboard?

A

eg.
sort < names

input is coming from file called “names”. Note this does not change the content of the file.

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

pipe

A

eg.
ls -l | grep “*.txt” | wc -l


pipe output of one command into another
eg.
command1 | command2
command2’s stdin comes from command1’s stfout

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

what’s the shebang?

A

!/bin/bash

Tells shell which interpreter to use when script is executed. Gives it the absolute path
It’s the first line of a shell script (or else it’ll be interpreted as a comment instead cuz of the #)

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

how to run a file?

A

./file

need the ./ if the directory it’s in is not in your PATH

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

difference between single and double quotes?

A

Double: will expand anything (eg. variable expansion)

single: it will be exactly what’s in the single quote with no expansions

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

echo

A

writes arguments to standard out.
there’s a \n after the echo line is executed. It also preserves white space

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

when would you use printf instead of echo?

A

when you want specific formatting

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

how to declare a variable? How to expand it?

A

variable=content
echo “$variable”

with NO SPACES when you declare it.
Need “” when you call it

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

what’s a positional parameter?

A

it accesses arguments passed into the script when you run it

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

$0

A

name of bash script

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

$1, $2

A

bash script arguments

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

$$

A

process ID of the current shell/script

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

$#

A

total number of arguments passed to script

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

$@

A

gives the value of all arguments passed as an ARRAY of SEPARATE things

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

$?

A

exit status of last executed command

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

$!

A

process ID of last executed command

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

$*

A

gives value of all arguments treated as a SINGLE STRING

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

what’s iteration

A

reprtition until a condition changes

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

test

A

Evaluate an expression.
aka [ ]
Returns a status code Indication if the expression is true or false?
“if” conditional syntax is just another way of using test

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

how is the “if” statement written in bash?

A

if [[ test ]]; then

elif [[ second test ]]; then

else

fi

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

how to test if one file is older than another?

A

if [[ file-one -ot file-two ]]; then

fi

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

what are the 3 loops?

A

for, while, until

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

are bash arrays only 1-D? (i.e. you can’t nest an array inside an array)

A

Yes, they’re only 1 dimensional

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

how to create an indexed array?

A

declare -a arr=(“1” “2” “3”)
or
arr=(“1” “2” “3”)

**notice they’re separated by space, not comma! I think it will keep the whitespace if you have “ “ ?)

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

how to access array values by index?

A

arr=(“1” “2” “3”)

echo “${arr[0]}”

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

how to find how many elements in indexed array?

A

arr=(“1” “2” “3”)

echo “${#arr[@]}”

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

how to create associative array?

A

it’s like a dictionary in python

declare -A person
person[“name”]=”Jan”
person[“age”]=”31”

**notice:
- it’s -A (not -a)
- integer still has “ “

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

how to print all values in associative array?

A

echo “${arr[@]}”

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

how to print all keys in associated array?

A

echo “${!arr[@]}”

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

how to print value by key in associative array?

A

echo “${arr[“key1”]}”

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

syntax of for loop

A

list=”1 2 3 4 5”

for item in $list; do

done

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

How to print 1-10 incrementing by 2?

A

for i in {01..10..2}; do
echo $i
done

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

while loop syntax

A

while [condition]; do

done

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

how to read contents of a file line by line with a while loop?

A

file=/etc/passwd

while read -r line; do
echo $line
done < “$file”

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

what does break do in a loop?

A

exit entire loop

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

what does continue do in a loop?

A

go to the next iteration of the loop

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

how to store output of a date in a variable?

A

now=$(date)

(Note: this will store the current time and will not update)

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

What command to use for troubleshooting? Where do you put it in your script?

A

set -x

put it right under the shebang

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

explain this code:

if [[ -f ~/.bashrc ]]; then
source ~/.bashrc
fi

A

Checks if the .bashrc file exists in the user’s home directory, and if it does, it executes the commands from that file within the current shell session

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

is .sh necessary for a shell script?

A

No, it’s an older convention.
Now, most shell scripts have no file extension

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

How many types of expansions are there? What are they?

A

7 types of expansions:
- brace expansion
- tilde expansion
- parameter and variable expansion
- command substitution
- arithmetic expansion
- word splitting
- filename expansion

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

You have:
file1
file2
file3

how do you list out all these files?

A

echo file{1..3}

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

what does tilde expansion do?

A

unquoted ~ expands to current user’s home directory (/home/username)

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

parameter and variable expansion basic syntax?

A

${parameter}

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

first=”Mickey”
last=”Mouse”

how do you print out Mickey_Mouse?

A

echo “${first}_${last}”

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

what does this print?

first=”Mickey”
last=”Mouse”
echo “$first_$last”

A

Mouse

(b/c you don’t have { }, so it doesn’t expand the variables properly)

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

how to print length of the variable values? (how many letters)

A

”${#variable}”

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

arr_one=( 1 2 3 4 )

how to return all the elements of arr_one indexed array?

A

echo ${arr_one[@]}

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

arr_one=( 1 2 3 4 )

how to return length of the indexed array?

A

echo ${#arr_one[@]}

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

what does this do? What does it return?

letters=”abc”
echo ${letters/abc/123}

A

It replaces characters. Returns 123

It will substitute the first occurrence of the pattern abc in the value of the variable letters with 123. /abc/ is the pattern to search for

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

Explain this. What does it print?

var_name=”some_variable”
some_variable=”Hello, world!”

echo “${!var_name}”

A

prints Hello, world!

! is indicating indirect expansion. It’s where you can use the value of a variable as the name of another variable and then expand it

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

What does this print?

name=”Nathan”
echo “${name:0:2}”
echo “${name:2:2}”

A

Na
th

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

how to get extension of a file?

A

${file##*.}
(file is a variable name)

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

now=$(date)

what does this do? What kind of substitution is this?

A

it stores date in “now”

This is a command substitution. Lets the output of a command to replace the command itself.

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

what is the arithmetic expansion syntax?

A

”$(( expression )) “

eg.
echo “$(( (3 + 4) * 5 ))”
(returns 35)

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

what does this return?
nums1=( $(echo “one two three”) )
nums2=( “$(echo one two three)” )
echo ${#nums1[@]} ${#nums2[@]}

A

3 1

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

What’s IFS?

A

Internal Field Separator.

Default is whitespace (space, tab, newline) (IFS=$’ \t\n’)

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

What do these do?
*
?
[ ]

A
  • matches any sequence of characters

? matches any single character

[ ] matches any characters enclosed inside

Note: They have to be un-quoted for it to be regarded as a pattern

93
Q

How to make 2 folders inside of each other?

A

mkdir -p folder1/folder2

94
Q

what do these do:

ls d*
ls dir?

A

ls d* will display any files and directories in the current directory that start with the letter d.

ls dir? will display any files and directories that start with dir and has 1 more letter

95
Q

case statements

A

alternative to if/then/else clauses

96
Q

general syntax of case statement?

A

case EXPRESSION in
pattern_1)
statements
;;
pattern_2)
statements
;;
*)
statements
;;
esac

97
Q

How to prompt user to enter something and store it in a variable called var1?

A

read -p “Enter something” var1

98
Q

how to prompt user to enter a letter and check if they entered A or B?

A

read -p “Enter a letter” character

case “$character” in
A)
echo “You entered A”
;;
B)
echo “You entered B”
;;
*)
echo “You did not enter A or B”
;;
esac

99
Q

what is a shell function?

A

a compound command that has been given a name. It’s a series of commands for later execution. Functions must be declared before they’re called

100
Q

general syntax of a function?

A

func_name() { function body }

101
Q

Make a function “say_hi” that takes user input as the name to say hi to. Then call the function

A

say_hi() {
echo “Hi $1”
}

say_hi “Bob”

Note: the argument is NOT in brackets.

102
Q

how to make a variable local?

A

use “local” keyword.

Use the word “local” during variable declaration.

eg.
local func_result=”some result”

103
Q

!/usr/bin/env bash

What does this return?

localretrn () {
local func_result=”some result”
echo “$func_result”
}

func_result=”$(localretrn)”
echo $func_result

A

some result

104
Q

!/usr/bin/env bash

Explain this:

This will print arguments passed to the function
printall() {
local names=$@
for name in $names; do
echo “arg to func: $name”
done
echo “Inside func: $0 is still: $0”
}

printall $@

A

printall $@ – passes all positional parameters to the printall function

105
Q

How to move cursor in vim?

A

h - left
j - down
k - up
l - right

106
Q

vim - how to move to top and bottom of screen

A

H - top
L - bottom

107
Q

vim - how to go to first and last line of document

A

gg - first
G - last

108
Q

vim - how to replace a single character

A

r

109
Q

vim - how to undo and redo?

A

u (small u) - undo
ctrl+r - redo

110
Q

vim - how to start visual mode

A

v (small v)

111
Q

vim - how to copy a line

A

yy

112
Q

vim - how to paste

A

p - paste after cursor
P - paste before cursor

113
Q

vim - how to delete a line

A

dd

114
Q

vim - how to write/save a file

A

:w

115
Q

vim - how to quit

A

:q
will fail if there are unsaved changes

116
Q

vim - how to append

A

must be in insert mode

a - append after cursor
A - append at end of line

117
Q

how to make a file?

A

touch filename

makes empty files if it doesn’t exist. If it exists, it updates the modification time

118
Q

how to search for manual page

A

man -k search-word

119
Q

how to move up a directory

A

cd ..

120
Q

how to move to root directory

A

cd /

121
Q

what’s pwd?

A

print working directory. gives you absolute path

122
Q

how to copy files/directories from one location to another

A

cp [options] source destination

-r copies recursively
-i prompts before overwriting
-u copies only when source file is newer
-a preserves permissions, ownership, timestamp

123
Q

how to move or rename files and directories?

A

mv [options] source destination

124
Q

how to delete an empty directory?

A

rmdir

125
Q

how to delete a file/directory that is not empty?

A

rm -rf file

126
Q

how to search for a file?

A

locate file.txt

use -i to ignore case sensitivity

127
Q

how to read contents of a file?

A

cat file

128
Q

how to display info about operating system?

A

uname

129
Q

how to change permissions

A

chmod

130
Q

how to change owner of file/dir?

A

chown [options] new_owner:new_group file

131
Q

3 types of journaling in ext3?

A

journal (slowest)
writeback (best performance; less consistent)
ordered (default; does not update filesystem metadeta)

132
Q

which filesystem is good for large file manipulation and high-end hardware performance?

A

XFS

133
Q

What is a swap file?

A

A form of virtual memory. Generates temporary storage space by replacing a section of memory in the RAM of a paused program

134
Q

how to find what type of filesystem your system uses?

A

df -T
then look at column “Type”

135
Q

which folder has stores configuration files?

A

/etc

136
Q

which folder contains temporary files that are erased when a computer shuts down?

A

/tmp

do not have to manually remove them

137
Q

which folder contains files and utilities shared between users?

A

/usr

138
Q

what’s an example of a pseudo-filesystem?

A

proc filesystem

139
Q

where do you find info about running processes?

A

/proc/<pid>

140
Q

what’s the logical “and” symbol?

A

&&

141
Q

what’s the logical “or” symbol?

A

||

142
Q

what signal is sent when you try dividing by 0?

A

SIGILL

143
Q

how to see a list of background processes?

A

jobs

144
Q

how to bring a background job to the foreground?

A

fg <job number>

145
Q

what (default) signal is send for the kill command?

A

SIGTERM

146
Q

how to forcibly quit a process?

A

kill -SIGKILL <PID>
or
kill -9 <PID>

147
Q

how to find the processes taking the most resources?

A

top
(the ones taking the most resources automatically float to the top)

148
Q

where do you find group information?

A

/etc/group

149
Q

how to view password expiration information?

A

sudo chage -l <user>

150
Q

how to change length of time for which user’s password is valid

A

chage

sudo chage -d 0 user
sets days to password expiration to 0 (must change password on first login)

sudo chage -M <# of days> user
max days before password expires

151
Q

What’s the minimum documentations in a program you write?

A
  • author
  • date
  • description of command
152
Q

test expressions/options for:
- existence of file
- regular file
- directory

A

-e for existance
-f for regular file (checks type of file)
- d for directory

153
Q

test expressions/options for integers:
- equality
inequality

A

-eq for equality
- ne for inequality
-gt for greater than
-lt
-ge for greater than or equals to
-le

154
Q

test expressions/options for strings:
- quality/identical
- inequality
- if it’s empty
- if it’s not empty
- logical AND
- logical OR

A
  • quality/identical: =
  • inequality: !=
  • if it’s empty: -z
  • if it’s not empty: -n
  • logical AND: -a
  • logical OR: -o
155
Q

what does (( … )) evaluate?

A

arithmetic expression.

156
Q

what does -z do in if/else statement?

A

tests if variable is empty
eg.
read name
if [[ -z $name ]]
then
…..

157
Q

what does “read” do?

A

read text from standard input, then store it in a variable

read [options] variable

158
Q

how to match lowercase letters?

A

[[:lower]]

159
Q

how to match letters h to o inclusive?

A

[h-o]

160
Q

help

A

view all shell built-ins

161
Q

system call interface

A

allows user-level processes to interact with the kernel

162
Q

What does the kernel do

A

it’s the lower level component that talks to hardware

163
Q

What terminals do Linux OS’ usually come with?

A

Gnome terminal (Gnome)
Konsol (KDE)

164
Q

What’s a shell?

A

It’s the shell that runs commands you type into the terminal. it’s a command line envrionment

165
Q

What’s a SSH? What is it used for?

A

SSH = Secure Shell protocol

It’s a way for securely sending commands to a computer over an unsecured network. SSH uses cryptography to authenticate and encrypt connects between devices.

Often used for controlling servers remotely, for managing infrastructure, and transferring files.

It has 2 keys: public (on server) and private (on host)

166
Q

What’s a utility

A

It’s a separate program.
Usually a binary in /usr/bin.
eg. mkdir

167
Q

$PATH

A

Show your existing path.

$PATH variable is an environment variable used to define the directories where the shell looks for executable files when you run a command.

168
Q

What’s a command

A

What you enter into the shell.
Utility followed by arguments.

169
Q

What is the wildcard?

A

*

170
Q

How many Vim basic modes are there? What are the 4 common ones?

A

7 basic modes.
Common ones: Normal, Insert, Visual, Command-line

171
Q

How to search for a man page?

A

man -k search-word

172
Q

What’s a pager?

A

man pages are viewed on a separate utility called a pager. Most common pager is “less”

173
Q

less

A

a pager that you can view man pages on

174
Q

How to search for a word in less?

A

/search-word

175
Q

Where is the vim configuration file

A

~/.vimrc

176
Q

How to apply changes after you make a change for vim configuration?

A

:source ~/.vimrc

177
Q

Where is the bash shell configuration file?

A

~/.bashrc

178
Q

What is a filesystem?

A

Methods and data structures operating systems use to keep track of files. It’s the way files are organized on the disk. Underlying rules for how data is stored.

179
Q

Filesystem Hierarchy Standard

A

Most Linux distro have files and directories organized acoording to this

180
Q

Where does the filesystem begin at?

A

It beings at the root directory / and branches out like a family tree

181
Q

What’s inside dev directory (/dev)?

A

Contains special or device files

182
Q

What’s inside the root directory (/)?

A

It’s the start of the tree, the beginning of our directory structure.
Inside are key directories used to store specific files on your system

183
Q

What’s inside bin directory (/bin)?

A

/bin is a symbolic link to /usr/bin

Historically stored utilities needed to run in single user mode.
Most binary files stored here.

184
Q

What’s inside proc directory (/proc)?

A

Contains a sub directory for each running process, which is named after the PID.

Proc is a pseudo filesystem.

185
Q

What’s inside home directory (/home)?

A

Regular user home directories are stored here.
eg. /home/bob

186
Q

What’s a pseudo filesystem?

A

A way to work with non-file data as though it were a file.

Advantage is that organizing and interacting with data can be handled like how you work with files.

187
Q

What is a symbolic link? (aka. softlink, symlink)

A

Indirect pointer to a file.
The directory entry contains pathname of the pointed-to-file. A pointer to the hard link to the file.
When you dereference a symbolic link, you follow the link to the target file.
Can create a symbolic link with “ln -s”

188
Q

how to create a symbolic link

A

ln -s [options] FILE LINK

(eg. ln -s source_file symbolic_link)

189
Q

How can you view links?

A

ls -l
Option links will appear with an arrow pointing to the file they link to. (eg. bin -> usr/bin/

190
Q

how to Find files based on file properties.

A

find [path] [options] [expression]

eg. find /path/to/search -type d -name “docs”

191
Q

how to execute a command on a file found by “find”

A

-exec
-exec <command></command> {} \;
-exec <command></command> {} +
(used with “find”)

eg.
find ./GFG -name smaple.txt -exec rm -i {} \;

192
Q

what is -ctime (used with “find”)

A

the time when the metadata of a file or directory (such as permissions, ownership, etc.) was last modified

193
Q

-mtime
(used with “find”)

A

search for files based on their modification time.

eg. -mtime +7 would search for files whose modification time is more than 7 days ago

eg. -mtime 0 to search for files whose modification time is exactly zero days ago (i.e., files that were modified today)

194
Q

Find patterns of text in a file. To search for text patterns within files or standard input, and then print lines that match those patterns.

A

grep

Uses (eg.): look for file based on contents of the file.

grep “search-word” file

eg. grep “pattern” file1.txt file2.txt

195
Q

Return found instances of search term within 2 lines above and below where search pattern was found (for context)

A

grep -C 2 search-word file

196
Q

Count number of times “set” was found in .bashrc file

A

grep -c “set” ~/.bashrc

197
Q

Return list of files that contain search pattern

A

grep -rl “search pattern” dir

198
Q

fc -list | grep -i “nerd”

A

fc = list fonts available
this means to find all of the nerd fonts you have installed.

199
Q

What’s a process?

A

Running instance of a program

200
Q

display information about all running processes in the system.

A

ps -e

201
Q

ps -e | grep vim

A

list all processes currently running on the system (ps -e), and then filter the output to only show lines that contain the word “vim” (grep vim).

202
Q

echo $?

A

view exit code of last command

203
Q

what’s an exit code?

A

When process terminates for any reason, it returns an exit code

204
Q

what does exit code 1 mean? 0?

A

0 = no error (success, did was it was told to do)
non-0 = error

205
Q

ctrl+r

A

“reverse history search” or “reverse incremental search.” Lets you search through your command history for previously entered commands.

206
Q

What is a signal used for?

A

a way for user (or another process) to communicate with a running process

207
Q

SIGINT

A

Interrupts a foreground process.
The signal sent when you press Ctrl+C

208
Q

SIGTERM

A

Terminate a process.
Graceful shutdown.
Lets process finish but stops child processes.

209
Q

SIGKILL

A

force quit immediately

210
Q

kill vs pkill

A

kill is installed on almost every distro. You have to give it a PID

pkill only needs a pattern that matches a process name. But it’s not as precise

211
Q

Orphan process

A

Can end up with these when you kill a process. Parent process killed but child process is left running and not adopted by parent process’ immediate descendant. These are problematic b/c they’re still taking up memory

212
Q

ps -e | grep -i systemd

A

list all processes currently running on the system (ps -e), and then filter the output to only show lines that contain the case-insensitive word “systemd” (grep -i systemd)

213
Q

ps -eo comm,pid,%cpu | grep -i systemd

A

list the command name, process ID, and CPU usage for all processes currently running on the system where the command name contains “systemd” (case-insensitive).

214
Q

ps -H

A

hierarchical view of processes, showing their relationships in a tree-like structure

215
Q

ps –forest

A

display a process tree in a hierarchical, tree-like format. This command is particularly useful for visualizing the parent-child relationships between processes and understanding the process hierarchy on the system. Has indentation and _

216
Q

top

A

To monitor system activity in real-time (it updates). It provides a dynamic, interactive view of system processes, CPU usage, memory usage, and other system resources.

h for help
q for quit
shift+V to toggle tree view

217
Q

htop

A

Gives overview of your system, like top, but easier to read and has colours.

218
Q

“nice” value

A

helps determine how much CPU time to give to a process. Lower nice value = higher priority (more CPU time)

219
Q

How many user and group owner(s) can a file have?

A

1 of each

220
Q

What types of users are there?

A

Human
System

221
Q

Why is UID 0?

A

Root

222
Q

What UID is reserved for system users?

A

UID 1-999

223
Q

arr_one=( 1 2 3 4 )

how to echo all the elements of the array?
how to echo the length of arr_one?

A

echo ${arr_one[@}}

echo ${#arr_one[@]}

224
Q

letter=”abc”

how to replace abc with 123 to echo 123?

A

echo ${letters/abc/123}

225
Q

prefix_a=one
prefix_b=two

echo ${!prefix_*}

What does this echo?
What does the ! do?

A

it echoes:
prefix_a prefix_b
(matches patterns that start with prefix_) (NOTE: it prints the VARIABLE name)

! is indirect expansion (value of the variable is used as name of another variable to expand)

226
Q

what’s the difference between:
$( )
and
$(( ))

A

$( ) is command substitution
$(( )) is arithmetic expansion

227
Q
A
228
Q
A