Topic 6 - Scripting and archiving Flashcards
this will create a .tar archive file named mylife.tar containing the life/ directory and its contents.
It will then proceed to verbose the files processed
what is the outcome of typing
tar –create –verbose –file=mylife.tar life/
into a linux terminal
this will decompress and extract the path and any files ending with burnet from the file mylife.tgz it will then print the files processed
what is the outcome of typing
tar –extract –verbose –file=mylife.tgz –wildcards ”*burnet“
into a linux terminal
this will decompress and extract the contents of the file mylife.tgz it will then print the files processed
what is the outcome of typing
tar –extract –verbose –file=mylife.tgz
into a linux terminal
does
tar
perform compression
no this command will only archive a directory and by itself does not perform any compression
although it is able to work with other commands that do perform compression
this is accomplished by using the following format:
Variable-name=value
No space should be used either side of the equals sign
in a linux script how do you declare a variable
no this command will only archive a directory and by itself does not perform any compression
although it is able to work with other commands that do perform compression
does
tar
perform compression
what was
tar (tape archive)
originally built for
this was originally developed to transfer files from very space limited hard drives to magnetic tapes and vice versa. However it became useful in creating an archive file that could be transported over the internet
lists the contents of the mylife.zip file (does not perform extraction)
what is the outcome of typing
unzip -l mylife.zip
into a linux terminal
what is the outcome of typing
unzip mylife.zip life/animals/
into a linux terminal
decompresses and extracts the directory and path life/animals/ from mylife.zip
what is the linux
tree
command used for
This is used to list the contents of a directory to the terminal window in a tree like format
what is the outcome of typing
bzip2 –verbose –keep mylife.tar
into a linux terminal
this will compress the file mylife.tar in the process preserving the original and creating a new file mylife.tar.bz2. it will then print information about the compression ratio
in linux how are
double quotes
handled
Anything wrapped inside these will be interpreted.
so spaces will be preserved, variables will be read and these are stripped after interpretation
decompresses and extracts the directory and path life/animals/ from mylife.zip
what is the outcome of typing
unzip mylife.zip life/animals/
into a linux terminal
what is
compression
this is the act of taking a file and reducing the number of bytes that it takes up, reducing storage space and bandwidth
this can be achieved by:
-
holding the argument place in a variable
- arg1=$1
- arg2=$2
-
hold all arguments given in a single variable
- args=$@
in linux what are the 2 ways that we can
read the arguments given by the user
in a linux script how do you declare a variable
this is accomplished by using the following format:
Variable-name=value
No space should be used either side of the equals sign
this will create an archive file and then compress it. the file will be named mylife.tgz and will contain the contents of the life/ directory. It will then continue to give verbose output about the archived files
what is the outcome of typing
tar –create –verbose –gzip –file=mylife.tgz life/
into a linux terminal
this will decompress and extract the file and path life/animals/insects from mylife.tgz it will then print the files processed
what is the outcome of typing
tar –extract –verbose –file=mylife.tgz life/animals/insects
into a linux terminal
what is the outcome of using
Read variable-name
in a linux script
this can be used to get input from the user and hold it in the variable variable-name
what is
archiving
this is the act of combining files and directories into a single file which can then be stored or copied
this will recursively compare the files in ~/work/life against the files in ~/extract/life
what is the outcome of typing
diff -r ~/work/life ~/extract/life
into a linux terminal
what is the outcome of typing
gzip mylife.tar
into a linux terminal
this will compress and replace the file mylife.tar to mylife.tar.gz
this can be achieved by enclosing the command and any options within brackets and appending a $ to the opening bracket
syntax
command-output=$(command-and-options)
in a linux script how can we hold the output of a command as a variable value
in a linux script what does the following accomplish
Today=$(date -I)
this will run the command
date -I
and the output will be stored as the value to the variable today
this will uncompress and replace the file mylife.tar.gz to mylife.tar
what is the outcome of typing
gunzip mylife.tar.gz
into a linux terminal
what is the outcome of typing
gzip –verbose –keep mylife.tar
into a linux terminal
this will compress the file mylife.tar in the process preserving the original and creating a new file mylife.tar.gz. it will then print information about the compression ratio
name a common cryptographic hash function used to produce
message digests
sha256 is one common hash function that is used to produce this
what are the file extensions for gzip
- on its own
- with tar using single extension
these include:
- on its own - .gz
- with tar using single extension -.tgz
what is the outcome of typing
tar –create –verbose –bzip2 –file=mylife.tbz life/
into a linux terminal
this will create an archive file and then compress it. the file will be named mylife.tbz and will contain the contents of the life/ directory. It will then continue to give verbose output about the archived files
This is used to list the contents of a directory to the terminal window in a tree like format
what is the linux
tree
command used for
this will display the contents of the archive file named life.tar in the terminal
what is the outcome of typing
tar –list –file=life.tar
into a linux terminal
what is the outcome of typing
tar –extract –verbose –file=mylife.tgz
into a linux terminal
this will decompress and extract the contents of the file mylife.tgz it will then print the files processed
NO
in this case tar will make use of the linux file command to find the type of compression used.
it can then use this information and execute the suitable decompression programme
when using tar to extract the contents of a compressed archive file. must you specify the compression that the file has used
where are
message digests
commonly used
these will normally be used on the internet
the creator of a file will post this along with the original file. the user can then download the file and run the same hashing algorithm to verify that this matches what has been posted online
this is accomplished by appending $ to the beginning of the variable name
$variable-name
in a linux script how do we access a variable
- variables created within a linux script - these exist only for as long as the script is executing
- environmental variables such as $PATH - these exist for the duration of the terminal session although any changes made to this via a linux script will outlast the scripts execution
what is the lifespan for each of the following:
- variables created within a linux script
- environmental variables such as $PATH
these are used to verify the integrity of files ensuring that the file is neither corrupted or tampered with
what are
message digests
used for
this is sometimes referred to as a
tarball
what is a
.tar file
sometimes referred to as
what is the outcome of typing
tar –create –verbose –gzip –file=mylife.tgz life/
into a linux terminal
this will create an archive file and then compress it. the file will be named mylife.tgz and will contain the contents of the life/ directory. It will then continue to give verbose output about the archived files
decompresses and extracts any files or directories ending with burnet from the archived file mylife.zip
what is the outcome of typing
unzip mylife.zip *burnet
into a linux terminal
these include:
- on its own - .gz
- with tar using single extension -.tgz
what are the file extensions for gzip
- on its own
- with tar using single extension
during this operation it will preserve:
- The structure of the directories
- The contents of files
- Owner of file
- File permissions
- Timestamps
name 5 pieces of information that the tar command will preserve when creating a .tar file
what are
message digests
used for
these are used to verify the integrity of files ensuring that the file is neither corrupted or tampered with
what is the outcome of typing
tar –list –file=life.tar
into a linux terminal
this will display the contents of the archive file named life.tar in the terminal
if a script does not contain the #! at the beginning of the script how can it be executed
if a script does not contain this then you must specify the name of the interpreter before the script name
why will
tar add padding
when creating an archive file
tar performs this since it was built to work with block devices such as tape drives
what this means is that each file starts at a new block. this makes it easier to pull out individual files
to fill in any gaps between the end of a file and a new block this is performed
what is a
.tar file
sometimes referred to as
this is sometimes referred to as a
tarball
to accomplish this the command is
chmod +x script-name
what is the command to make a script containing the #! executable
this is the act of taking a file and reducing the number of bytes that it takes up, reducing storage space and bandwidth
what is
compression
decompresses and extracts the contents of mylife.zip file
what is the outcome of typing
unzip mylife.zip
into a linux terminal
this will run the command
date -I
and the output will be stored as the value to the variable today
in a linux script what does the following accomplish
Today=$(date -I)
name 2 common compression programs available on linux
these include:
- gzip (GNU zip)
- bzip2
note
bzip2 is usually more space efficient than gzip
this will compress the file mylife.tar in the process preserving the original and creating a new file mylife.tar.gz. it will then print information about the compression ratio
what is the outcome of typing
gzip –verbose –keep mylife.tar
into a linux terminal
what is the outcome of typing
diff -r ~/work/life ~/extract/life
into a linux terminal
this will recursively compare the files in ~/work/life against the files in ~/extract/life
If a script would be useful for all users on the system then where is it normally placed
in this case the script should be added to
/usr/local/bin
this location will already be in the $PATH and so is accessible for all users
sha256 is one common hash function that is used to produce this
name a common cryptographic hash function used to produce
message digests
how can you execute a script without specifying its path
to accomplish this the script must be in one of the directories in which bash will search for programs
these can be found using echo $PATH
in a linux script how do we access a variable
this is accomplished by appending $ to the beginning of the variable name
$variable-name
what is the outcome of typing
unzip mylife.zip *burnet
into a linux terminal
decompresses and extracts any files or directories ending with burnet from the archived file mylife.zip
this was originally developed to transfer files from very space limited hard drives to magnetic tapes and vice versa. However it became useful in creating an archive file that could be transported over the internet
what was
tar (tape archive)
originally built for
what is the outcome of typing
unzip mylife.zip
into a linux terminal
decompresses and extracts the contents of mylife.zip file
- how does the zip software differ from the tar software
- what makes zip so popular
- how does the zip software differ from the tar software - tar on its own does not perform compression however zip has archiving and compression built in and carries it out by default
- what makes zip so popular - zip is supported by all major operating systems making it the archive format for sharing files between operating systems
what is
tar (tape archive)
This is an archiving program that can store multiple files into a single file (an archive) and also extract those files from the archive
in this case the script should be added to
~/bin
and then this path should be added to the $PATH
If a script is for a single user on the system then where is it custom to add it to
when using tar to extract the contents of a compressed archive file. must you specify the compression that the file has used
NO
in this case tar will make use of the linux file command to find the type of compression used.
it can then use this information and execute the suitable decompression programme
- how does the zip software differ from the tar software - tar on its own does not perform compression however zip has archiving and compression built in and carries it out by default
- what makes zip so popular - zip is supported by all major operating systems making it the archive format for sharing files between operating systems
- how does the zip software differ from the tar software
- what makes zip so popular
what is the outcome of typing
unzip -l mylife.zip
into a linux terminal
lists the contents of the mylife.zip file (does not perform extraction)
what is the outcome of typing
tar –extract –verbose –file=mylife.tgz –wildcards ”*burnet“
into a linux terminal
this will decompress and extract the path and any files ending with burnet from the file mylife.tgz it will then print the files processed
this is an accronym for
tape archive
what does
tar
stand for
this will compress and replace the file mylife.tar to mylife.tar.gz
what is the outcome of typing
gzip mylife.tar
into a linux terminal
the syntax for this is:
For variable-name in iterable
Do
Looped code here
Done
what is the syntax for a
linux for loop
what is the outcome of typing
zip -r mylife.zip life/
into a linux terminal
this recursively archives and compresses the life/ directory into the mylife.zip file
what is the outcome of typing
tar –extract –verbose –file=life.tar
into a linux terminal
this will extract the files from the archive file life.tar and then verbosely list the processed files in the terminal window
in this case the script should be added to
/usr/local/bin
this location will already be in the $PATH and so is accessible for all users
If a script would be useful for all users on the system then where is it normally placed
this recursively archives and compresses the life/ directory into the mylife.zip file
what is the outcome of typing
zip -r mylife.zip life/
into a linux terminal
to accomplish this the script must be in one of the directories in which bash will search for programs
these can be found using echo $PATH
how can you execute a script without specifying its path
these will normally be used on the internet
the creator of a file will post this along with the original file. the user can then download the file and run the same hashing algorithm to verify that this matches what has been posted online
where are
message digests
commonly used
these include:
- on its own - .bz2
- with tar using a single extension - .tbz
what are the file extensions for bzip2
- on its own
- with tar using a single extension
what is the syntax for a
linux for loop
the syntax for this is:
For variable-name in iterable
Do
Looped code here
Done
in linux how are
single quotes
handled
Anything wrapped inside these is taken literally and is not interpreted.
in this case a variable would be seen as text and not read
Anything wrapped inside these will be interpreted.
so spaces will be preserved, variables will be read and these are stripped after interpretation
in linux how are
double quotes
handled
what is the command to make a script containing the #! executable
to accomplish this the command is
chmod +x script-name
this will create an archive file and then compress it. the file will be named mylife.tbz and will contain the contents of the life/ directory. It will then continue to give verbose output about the archived files
what is the outcome of typing
tar –create –verbose –bzip2 –file=mylife.tbz life/
into a linux terminal
name 5 pieces of information that the tar command will preserve when creating a .tar file
during this operation it will preserve:
- The structure of the directories
- The contents of files
- Owner of file
- File permissions
- Timestamps
This is used to print or check sha256 checksums
what is the linux
sha256sum
command used for
This is an archiving program that can store multiple files into a single file (an archive) and also extract those files from the archive
what is
tar (tape archive)
what is the outcome of typing
gunzip mylife.tar.gz
into a linux terminal
this will uncompress and replace the file mylife.tar.gz to mylife.tar
what is the outcome of typing
tar –create –verbose –file=mylife.tar life/
into a linux terminal
this will create a .tar archive file named mylife.tar containing the life/ directory and its contents.
It will then proceed to verbose the files processed
If a script is for a single user on the system then where is it custom to add it to
in this case the script should be added to
~/bin
and then this path should be added to the $PATH
this will compress the file mylife.tar in the process preserving the original and creating a new file mylife.tar.bz2. it will then print information about the compression ratio
what is the outcome of typing
bzip2 –verbose –keep mylife.tar
into a linux terminal
this can be used to get input from the user and hold it in the variable variable-name
what is the outcome of using
Read variable-name
in a linux script
if a script does not contain this then you must specify the name of the interpreter before the script name
if a script does not contain the #! at the beginning of the script how can it be executed
this is the act of combining files and directories into a single file which can then be stored or copied
what is
archiving
in linux what are the 2 ways that we can
read the arguments given by the user
this can be achieved by:
-
holding the argument place in a variable
- arg1=$1
- arg2=$2
-
hold all arguments given in a single variable
- args=$@
this will extract the files from the archive file life.tar and then verbosely list the processed files in the terminal window
what is the outcome of typing
tar –extract –verbose –file=life.tar
into a linux terminal
This is used to compare files line for line. If the files are the same then the command ends silently
what is the linux
diff
command used for
what are the file extensions for bzip2
- on its own
- with tar using a single extension
these include:
- on its own - .bz2
- with tar using a single extension - .tbz
Anything wrapped inside these is taken literally and is not interpreted.
in this case a variable would be seen as text and not read
in linux how are
single quotes
handled
what is the lifespan for each of the following:
- variables created within a linux script
- environmental variables such as $PATH
- variables created within a linux script - these exist only for as long as the script is executing
- environmental variables such as $PATH - these exist for the duration of the terminal session although any changes made to this via a linux script will outlast the scripts execution
what is the linux
diff
command used for
This is used to compare files line for line. If the files are the same then the command ends silently
in a linux script how can we hold the output of a command as a variable value
this can be achieved by enclosing the command and any options within brackets and appending a $ to the opening bracket
syntax
command-output=$(command-and-options)
tar performs this since it was built to work with block devices such as tape drives
what this means is that each file starts at a new block. this makes it easier to pull out individual files
to fill in any gaps between the end of a file and a new block this is performed
why will
tar add padding
when creating an archive file
what is the linux
sha256sum
command used for
This is used to print or check sha256 checksums
what is the outcome of typing
tar –extract –verbose –file=mylife.tgz life/animals/insects
into a linux terminal
this will decompress and extract the file and path life/animals/insects from mylife.tgz it will then print the files processed
these include:
- gzip (GNU zip)
- bzip2
note
bzip2 is usually more space efficient than gzip
name 2 common compression programs available on linux
what does
tar
stand for
this is an accronym for
tape archive