Answer:
See explaination
Explanation:
Bash Script:
#!/bin/bash
echo "Creating files a.txt, b.txt, c.txt..."
#1
# Create a random number between 1700 to 1800. This is the Kb we are looking for
# And then multiply by 1000 (1Kb = 1000 bytes)
r=$(( ($RANDOM % 100 + 1700) * 1000 ))
# head -c specifies the number of chars to read from the input,
# which is /dev/urandom stream in this case.
# Ideally we should have just used r*1000 to specify number of bytes,
# but since we are pipelining it to base64 to get text chars,
# this conversion will happen in the ratio of 4/3.
head -c $r /dev/urandom | base64 > a.txt
# Hence, we trunctate the file to the exact (random number we generated * 1000) bytes
truncate -s $r a.txt
r=$(( ($RANDOM % 100 + 1700) * 1000 ));
head -c $r /dev/urandom | base64 > b.txt
truncate -s $r b.txt
r=$(( ($RANDOM % 100 + 1700) * 1000 ));
head -c $r /dev/urandom | base64 > c.txt
truncate -s $r c.txt
#3 Use tar command to create all_three.tar from a.txt, b.txt, c.txt
tar -cf all_three.tar a.txt b.txt c.txt
echo $(stat -c "%n: %s" all_three.tar)
#4 Gzip a.txt into a.gz (without deleting the original file) and so on
gzip -c a.txt > a.gz
gzip -c b.txt > b.gz
gzip -c c.txt > c.gz
echo $(stat -c "%n: %s " a.gz b.gz c.gz)
#5 Gzip a.txt, b.txt, c.txt into all_three.gz
gzip -c a.txt b.txt c.txt > all_three.gz
echo $(stat -c "%n: %s" all_three.gz)
#6 Gzip the all_three.tar we created in #3
gzip -c all_three.tar > all_three.tar.gz
echo $(stat -c "%n: %s" all_three.tar.gz)
# Check all files we created with ls command sorted by time in ascending order
ls -ltr a.txt b.txt c.txt all_three.tar a.gz b.gz c.gz all_three.gz all_three.tar.gz