Lesson 3 Flashcards

1
Q

How does compression work?

A

By replacing repetitive patterns in data. For example finding a common word and replacing it with something else then creating a map to that replacement (obv more complex)

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

What are the two types of compression?

A

Lossless and Lossy

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

When is lossy compression often used?

A

For images, video or audio where loss in the original data has a marginal effect

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

Name some common lossless compression tools

A

bzip2, gzip, xz

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

What is the most common archiving tool?

A

tar

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

how do you uncompress? name the common commands

A

bunzip2, gunzip, unxz

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

How can you increase or decrease the level of compression?

A

By using -1 through -9…common among all compression tools

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

what is the syntax for a tar command to compress?

A

tar -cf newfile pathtoarchive

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

what is the syntax to untar?

A

tar -xf <file/path>

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

When using tar with gzip, bgzip2 and xz what are the commands?

A

gzip = tar -xzf
bzip2 = tar -xjf
xz = tar -xJf

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

syntax to zip recursively

A

zip -r filename filepath

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

syntax to unzip

A

unzip filename

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

how to output the contents of a compressed file?

A

zcat gzip, bzcat for bzip2

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

how do add a file to a compressed tar?

A

First you need to uncompress it so gunzip or bunzip2 or unxz…then use tar uf to add a new file

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

how to view contents of a tar without extracting it?

A

tar -tf filename

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

Which tar option instructs tar to include the leading “/” in the absolute paths?

A

-P

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

Does zip support multiple compression levels?

A

Yes same as the other compression tools

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

When extracting and archive, does tar support wildcards?

A

Yes with the –wildcards option

19
Q

How can you ensure decompressed files are lossless?

A

bzip2, gzip, and xz all have checksums built in to ensure this

20
Q

What is I/O redirection?

A

Enabled you to redirect information from or to a command by using a text file

21
Q

Which character to redirect std out to a file?

A

> for example echo "hello world" > text

22
Q

Which characters to redirect std out but add to a file?

A

>>

23
Q

Which characters to redirect errors to a file?

A

2>

24
Q

How to redirect standard input to a command?

A

< example:
cat < text

25
Q

what does &> and &» do?

A

They redirect BOTH std out and errors to the file, &» just appends to it

26
Q

explain how the cut command works

A

First you give it the column with -f <number> and then a delimiter to make columns on with -d</number>

27
Q

what does -f do with the tail command?

A

Lives updates the file as you have it open so you can follow logs, etc

28
Q

with tail and head how can you specify the number of lines to show?

A

-n <number>

29
Q

with sort command how can you reverse the sort?

A

-r command

30
Q

Using grep, how can you search a file for certain string?

A

grep word filename

31
Q

name some common grep options

A

-i = case insensitive
-r = recursive
-c = includes count of matches
-v = invert the match
-E = used for regex (needed for *, +, ?)

32
Q

Using regex with grep, what are the starting and end marking characters?

A

start = ^
end = $

33
Q

Grep syntax for “OR”

A

grep -E "foo|bar" filename

34
Q

what does the question mark operator do?

A

it makes the preceding pattern optional (zero or one)

35
Q

What does it mean to define the interpreter?

A

use which bash to determine the type of interpreter you want to use as the shebang

36
Q

in bash, how can I assign a variable to an input from the command line?

A

foo=$1

applies from 1-9

37
Q

How to get the number of arguments passed into a bash script?

A

$#

38
Q

what does bash if then syntax look like?

A

```base
if [ condition ]
then

else

fi
~~~

39
Q

List common bash comparison operators

A

```bash
-eq
-ne
-gt
-ge
-lt
-le
~~~

40
Q

how to get the exit code of the previously run command?

A

echo $?

41
Q

What does the wildcard character $@ or $*

A

Contains all arguments passed to the script in an array

42
Q

with echo how can you suppress new lines?

A

-n

43
Q

what does “shift” do in bash?

A

Removes the first element of an array