Lesson 3 Flashcards
How does compression work?
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)
What are the two types of compression?
Lossless and Lossy
When is lossy compression often used?
For images, video or audio where loss in the original data has a marginal effect
Name some common lossless compression tools
bzip2, gzip, xz
What is the most common archiving tool?
tar
how do you uncompress? name the common commands
bunzip2, gunzip, unxz
How can you increase or decrease the level of compression?
By using -1
through -9
…common among all compression tools
what is the syntax for a tar command to compress?
tar -cf newfile pathtoarchive
what is the syntax to untar?
tar -xf <file/path>
When using tar with gzip, bgzip2 and xz what are the commands?
gzip = tar -xzf
bzip2 = tar -xjf
xz = tar -xJf
syntax to zip recursively
zip -r filename filepath
syntax to unzip
unzip filename
how to output the contents of a compressed file?
zcat gzip, bzcat for bzip2
how do add a file to a compressed tar?
First you need to uncompress it so gunzip or bunzip2 or unxz…then use tar uf to add a new file
how to view contents of a tar without extracting it?
tar -tf filename
Which tar option instructs tar to include the leading “/” in the absolute paths?
-P
Does zip support multiple compression levels?
Yes same as the other compression tools
When extracting and archive, does tar support wildcards?
Yes with the –wildcards option
How can you ensure decompressed files are lossless?
bzip2, gzip, and xz all have checksums built in to ensure this
What is I/O redirection?
Enabled you to redirect information from or to a command by using a text file
Which character to redirect std out to a file?
>
for example echo "hello world" > text
Which characters to redirect std out but add to a file?
>>
Which characters to redirect errors to a file?
2>
How to redirect standard input to a command?
<
example: cat < text
what does &> and &» do?
They redirect BOTH std out and errors to the file, &» just appends to it
explain how the cut command works
First you give it the column with -f <number> and then a delimiter to make columns on with -d</number>
what does -f do with the tail command?
Lives updates the file as you have it open so you can follow logs, etc
with tail and head how can you specify the number of lines to show?
-n <number>
with sort command how can you reverse the sort?
-r command
Using grep, how can you search a file for certain string?
grep word filename
name some common grep options
-i = case insensitive
-r = recursive
-c = includes count of matches
-v = invert the match
-E = used for regex (needed for *, +, ?)
Using regex with grep, what are the starting and end marking characters?
start = ^
end = $
Grep syntax for “OR”
grep -E "foo|bar" filename
what does the question mark operator do?
it makes the preceding pattern optional (zero or one)
What does it mean to define the interpreter?
use which bash
to determine the type of interpreter you want to use as the shebang
in bash, how can I assign a variable to an input from the command line?
foo=$1
applies from 1-9
How to get the number of arguments passed into a bash script?
$#
what does bash if then syntax look like?
```base
if [ condition ]
then
…
else
…
fi
~~~
List common bash comparison operators
```bash
-eq
-ne
-gt
-ge
-lt
-le
~~~
how to get the exit code of the previously run command?
echo $?
What does the wildcard character $@ or $*
Contains all arguments passed to the script in an array
with echo how can you suppress new lines?
-n
what does “shift” do in bash?
Removes the first element of an array