Week 8 Flashcards

1
Q

What three files are opened by default when a process starts

A

stdin, stdout, stderr

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

What is the purpose of a pipe

A

To put the output of one program as the input to another
ex ls | grep ‘foo’

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

What are the file descriptors of the three default files? and what describes them

A

stdin = 0, by default a read only file
stdout = 1, by default a write only file
stderr = 2, by default a write only file used for error and non-normal messages

No argument is by default 0 or 1
ex mycmd > out.txt 2>&1 places stdout to out.txt, and assigns stderr (2) to what stdout is pointing to (out.txt)

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

How do you connect inputs, and outputs

A

<, >. doing > places it in something < reads from
ex: mycmd <infile.txt

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

What are all the shell variables and what do they do

A

$0 - name of shell
$# - number of args
$1 - first arg
$* - all args seperated by spaces
$? - exit code of last cmd (0 = success)

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

Shell Script Definition?

A

a text file containing commands to be executed for a shell

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

How do we flip (flick) the execution bit (bean)

A

chmod +x file.extension

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

What are the different magic number lines

A

0x7F E L F - File contains linux binary code
M Z - File contains windows binary code
#! - path to the shell

Default: uses default shell

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

What does shift do?

A

Shifts the position arguments.
EX: example.sh 1 2 3
while(($#>0))
do
echo $1
shift
done

output is 1, 2, 3

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

What are the differences between (()) and [[]]

A

(()) - integer arithmetic ( you can assign variables within this ) $ not required
[[]] - true/false comparison between strings or files

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

what files are called when a new shell file starts

A

.bash_profile - read whenever a login shell starts
-bashrc - read when any bash shells are started

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

What are the different flags for find?

A

-type -size -time -name
-iname -atime +(time) -or

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

what do -f -d -l do?

A

-f = file
-d = directory
-l = link

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

Whats the difference between -name and -iname

A

-iname is case insensitive

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

What does find do ?

A

searches every file within a given list of directives

ex: find /home/student -name ‘*.txt’

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

What actions can you pass to find?

A

-print (default )
-delete
-exec

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

what does a2ps and lpr do?

A

lpr prints a file, a2ps converts the file to postscript and sends to stdout

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

What does grep do?

A

Searches line by line through fiels to find a regex (stdin by default)

ex: grep pattern file1 file2

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

What do these do in order? (GREP)
-i : -w : -v : -H : -h : -l : -q

A

case insensitive match, match must be the whole word,
lines that DONT match,
shows names of files,
do not show names of files ( default ),
only shows file names (not lines)
print nothing

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

What are the exit statuses of grep?

A

0 - atleast 1 match, 1- no match, 2 - error

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

What are the three types of regex? Give a description of each

A

Globbing - Method used by the shell and find to match filenames/paths used by shell and find using wildcards
normal regex - pattern matching syntax used by tools for string matching
extended regex - more advanced pattern matching (enabled with -E in grep and sed) which incldues addition features (+, ?, |, ())

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

What do the following normal regex do?
.

$
\
*
[]
[^]

A

. - matches any 1 char
^ -matches beginning of line
$ -matches end of line
\ - negates special meaning of char i.e., .
* - . but repeated ex xy*z would find xyyyyyyz xyyz…
[] - . but with any of the characters specified
[^] - match any character NOT specified in this list ex [^0-9] matches anything not a digit

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

What shell variable contains the PID of the shell?
Whats it useful for?

A

$$
Creating unique names

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

What directory is writable by all users, and can be used to store the output of commands (for a short time)

A

/tmp

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
What does sed do?
stream editor, reads from a stdin or a file ,and writes to stdout editing one line at a time from a given edit script
10
What does sed -e 's/foo/bar/g' do?
replaces every foo with bar globally. if the g wasnt there, it would only do the first match.
10
What does cut -d : -f 7 do?
-d : sets the delimited to :. and -f 7 picks out the svent field
11
What is a file system?
Abstract layer about secondary storage. i.e., users interact with files and directories but the actual representation fo storage is left to OS. It' responsible for allocating space on secondary stages.
11
What does putting & do in the replacement of sed?
places the replacement value exactly where the & is ex: sed -e 's/xyz*y/--&-- /' infile: the xyzzy fell = the --xyzzy-- fell
12
What does "tr" do?
translates characters in input to output (only uses stdin -> stdout, need redirection to use files) ex: echo "hello world" | tr 'a-z' 'A-Z' = HELLO WORLD
12
how do we specify which lines we want to modify with sed?
put it in the string o.e., sed -e '5,7 s/a/b/' only replaces lines 5-7 a's with b's
13
What does this do? and what of importance is it using? Sed -e “s/XXX/$var1/” << END1 This is some constant text embedded in the shell script. The value of var1 is XXX. END1
Substitutes the XXX with the value of var1 in the embedded document Here document (embedded document)
14
What are the different File Attributes?
Name, identifier, type, location, size, protection, time, date, user identification
15
Direct File Access
A way of accessing file information directly through the use of a known location or block, without needing to process previous data.
15
What is indexing?
a technique that involves storing records in blocks of a file or database. each record is associated with a key.
15
What are the different types of file access?
Sequential, direct access, indexed access
15
What's the definition of a directory structure?
A way of organizing files in a hierarchical format, where directories can contain files ando ther subdirectories. It mapes file names to physical storage locations, and supports various operations.
15
Whats a persistent B* tree
an improvement on a persistent B tree. It notably: Keeps nodes more full by redistributing keys between nodes more aggresively, holds more child pointers per nodes
15
Whats a persistent B tree
A self balancing search tree used in filesystems and databases. Each node contains multiple keys and child pointers. All changes are non destructive (it creates a new version of the tree each edit)
16
Directory or file may have more than one name. T + F
T
16
What is a two level directory?
The top level of the disk is a directory, second level is made up of user directories + 1 directory for sys commands
16
What does acyclic mean in terms of directories?
More than one path or a dir or a file
17
Directories must have a unique parent T or F
T
17
Whats a key difference between directories and files?
Files can be shared, directories cant
17
What is a symbolic link?
A file with special attributes that contains the path to a real file or dir
18
What is a partition?
a subset of the disk
19
In earlier version of windows and unix systems, how was the disk divided?
First 512 byte block was the legacy MBR, and the rest of the disk was divided into at most 4 primary partitions, with however many sub partitions as necessary
20
How is the modern GUID system laid out?
GPT header, partition table 31 blocks 2-33, secondary GPT header, Protective MBR,
21
What was the layout of the legacy MBR?
It consisted of a partition table and a boot code (446 bytes)
22
What is a GPT header?
Holds pointers to the partition tables first and last usable block
23
What's a partition table?
Holds records on where each partition sits in memory, boot information and meta data
24
What is the purpose of a protective MBR
prevents the legacy systems from corrupting the rest of the disk. Holds one partition of unknown type
25
Why do we have 2 GPT headers in a GUID partition table?
Incase the first one becomes corrupted
26
What is the "EFI systems partition"
One of the partitions in the GUID, it has it's own file system format and contains info on HOW to boot the system. i.e., if we have a linux & windows partition, the EFI contasin enough space for the bootcode to load each one.
27
What is a boot control block?
Hubert smell's like he looks. Silly. Block containing code to start the OS. Not big enough to hold the actual OS.
27
What is the PCB (Partition control blocK)
Controls the contents of the partition. It can free lists, counters dates, etc. The first block of the partition (usually) and holds the list of free blocks that are available.
27
Whats the FCB? (file control block)
one for each file, contains info such as file id, owner, size, aTimes and the location of the data blocks. In linux, its referred to as an inode.
27
What happens when we mount a partition?
Reads the PCB and sets up internal data structures such as buffers etc. Then stores it in the mount table.
27
What is a swap partition?
A designated space on a storage device used by the OS as virtual memory. Essentially provides extra VM by using disk space when physical ram is full.
27
What are the different levels of the file system?
Logical file system (Dir structure, prot, perms) File organization (logical block management Basic File System (reads and writes blocks) I/O Control Devices
27
Whats a mount point?
It's essentially the top level directory or root directory of your mounted device. Any directory can hold a mount point. example: /huberts-CP-device/....
27
What is the mount table?
holds info about each mounted partition, and the file system inside of it
28
What is the Per Process File Table?
Holds a reference to the system wide file table, and the current file position for this process. It's necessary for each file so one process doesn't pick up from the end what another process started.
28
What is the System Wide File?
Holds info from each FCB on every open file.
28
What happens when we open a file?
- Search the directory structure (could be cached in mem) for the file identifier - See if the FCB is already in memory (System file table), copy into memory if its not and inc counter ( counter = num processes accessing ) - Allocate entry in process file table. Point to the systme file table, allocate bufffers and initialize the current file poistion - return a pointer or index to process FCB
29
What happens when we close a file?
- use pointer or index to access the process's FCB - decrement counter. If counter is 0 (last process with file open), mark the FCB for deletion - Free process FCB
29
What is contiguous allocation?
The data blocks for a file are stored next to each other on the disk
30
What is indexed allocation?
Instead of storing data blocks directly, the system uses index blocks that hold pointers to the actual data blocks of the files.
30
What is the structure of an INODE?
Holds general information such as the filetype, permissions, owner, group size Holds 12 direct pointers to data blocks. Holds 3 "indirect" pointers to other tables for indirect data block management.
30
What is linked allocation
Each files blocks are not stored together, but instead each block points to the next block in the file Uses a FAT (file allocation table) to store the pointers. *FAT groups blocks into clusters, and the table is kept in memory.