Linux Up Skill – Day 16

L

Time to work through lesson 16 of the Linux Up Skill Challenge. Today’s lesson is called “Archiving and compressing.” I feel like I am already familiar with Tar and GnuZip so this should be a pretty quick one. Let’s dive in!

The lesson starts with a discussion on tar and gzip which is a nice refresher to actually think about the different parts of the process. I had no idea tar was originally short for tape archive, that’s neat! It also covers what the common switches cvzf each do. Today’s tasks include:

  • Check the resource links to better understand today’s lesson.
  • Use tar to create an archive copy of some files and check the resulting size.
  • Run the same command, but this time use the -z to compress – and check the file size.
  • Copy your archive to /tmp and extract each there to test that it works.

The first link talks about 18 tar commands to learn. The first thing that catches my eye is bz2, which is something I have not used previously. It looks like it could greatly come in handy when trying to package a huge number of log files. Next it talks about using tar to decompress and extract. I have always used unrar to decompress and extract in the past. So I’ll have to pay close attention to try and use untar instead through the lesson. The second link in the lesson just gives more examples of how to use tar.

Time now to log onto my server. I have a number of image files under /home/david/images from a previous lesson. That should be a fine test to archive.

david@linux-up-skill:/home/david# tar -cvf test-tar-7-11-2022.tar images/
images/
images/323.jpg_large.jpg
images/2022-04-09 06_03_34-.png
images/video_image-CiaNV9giv6.jpeg
images/2022-04-28 07_52_09-.png
images/2022-03-21 15_20_43-.png
images/2022-06-02 06_10_50-.png
images/obi-wan-kenobi-meme.jpg
images/2022-06-01 19_13_03-.png
images/2022-03-24 16_09_55-.png
david@linux-up-skill:/home/david# tar -cvzf test-2-tar-7-11-2022.tar.gz images/
images/
images/323.jpg_large.jpg
images/2022-04-09 06_03_34-.png
images/video_image-CiaNV9giv6.jpeg
images/2022-04-28 07_52_09-.png
images/2022-03-21 15_20_43-.png
images/2022-06-02 06_10_50-.png
images/obi-wan-kenobi-meme.jpg
images/2022-06-01 19_13_03-.png
images/2022-03-24 16_09_55-.png
david@linux-up-skill:/home/david# tar -cvjf test-34-tar-7-11-2022.tar.bz2 images/
images/
images/323.jpg_large.jpg
images/2022-04-09 06_03_34-.png
images/video_image-CiaNV9giv6.jpeg
images/2022-04-28 07_52_09-.png
images/2022-03-21 15_20_43-.png
images/2022-06-02 06_10_50-.png
images/obi-wan-kenobi-meme.jpg
images/2022-06-01 19_13_03-.png
images/2022-03-24 16_09_55-.png
david@linux-up-skill:/home/david# ls
day5description.txt  test                          testfile
images               test-2-tar-7-11-2022.tar.gz   test-tar-7-11-2022.tar
j                    test-3-tar-7-11-2022.tar.bz2  tuesday.txt

So I made the files easily enough. That I’m familiar with. What was the next step? Oh yeah I was suppose to check on the file size. I remember from the link that I can use the tar command to check on file size. Lets do that instead of ls -la. The link says you should use tar -czf filename | wc -c to check the size but this gives me a rather funny error of:

david@linux-up-skill:/home/david# tar -czf test-tar-7-11-2022.tar | wc -c
tar: Cowardly refusing to create an empty archive
Try 'tar --help' or 'tar --usage' for more information.

Well I see my problem I think. I missed a character in my last command.

david@linux-up-skill:/home/david# tar -czf - test-tar-7-11-2022.tar | wc -c
2322163
david@linux-up-skill:/home/david# tar -czf - test-2-tar-7-11-2022.tar.gz | wc -c
2322597
david@linux-up-skill:/home/david# tar -czf - test-3-tar-7-11-2022.tar.bz2 | wc -c
2352263

My compression seems to have not shrunk the size of my archive. Probably because I was using compressed images to begin with. Let’s move on to copying the archive files and extract them again.

david@linux-up-skill:/home/david# cp test-tar-7-11-2022.tar /tmp/
david@linux-up-skill:/home/david# cp test-2-tar-7-11-2022.tar.gz test-3-tar-7-11-2022.tar.bz2 /tmp/
david@linux-up-skill:/home/david# cd tmp
bash: cd: tmp: No such file or directory
david@linux-up-skill:/home/david# cd /tmp/
david@linux-up-skill:/tmp# ls
snap.lxd
systemd-private-d1b3e5f26c924d11b8145debfba2cb36-apache2.service-Ijf6kg
systemd-private-d1b3e5f26c924d11b8145debfba2cb36-ModemManager.service-4etjIi
systemd-private-d1b3e5f26c924d11b8145debfba2cb36-systemd-logind.service-CYUQ9i
systemd-private-d1b3e5f26c924d11b8145debfba2cb36-systemd-resolved.service-eo5iKh
systemd-private-d1b3e5f26c924d11b8145debfba2cb36-systemd-timesyncd.service-IwuMch
test-2-tar-7-11-2022.tar.gz
test-3-tar-7-11-2022.tar.bz2
test-tar-7-11-2022.tar
david@linux-up-skill:/home/david# cp test-tar-7-11-2022.tar test-2-tar-7-11-2022.tar.gz test-3-tar-7-11-2022.tar.bz2 /tmp/
david@linux-up-skill:/home/david# cd /tmp/
david@linux-up-skill:/tmp# ls

test-2-tar-7-11-2022.tar.gz
test-3-tar-7-11-2022.tar.bz2
test-tar-7-11-2022.tar
david@linux-up-skill:/tmp# tar -xvf test-tar-7-11-2022.tar images
images/
images/323.jpg_large.jpg
images/2022-04-09 06_03_34-.png
images/video_image-CiaNV9giv6.jpeg
images/2022-04-28 07_52_09-.png
images/2022-03-21 15_20_43-.png
images/2022-06-02 06_10_50-.png
images/obi-wan-kenobi-meme.jpg
images/2022-06-01 19_13_03-.png
images/2022-03-24 16_09_55-.png
david@linux-up-skill:/tmp# ls /tmp/images/
'2022-03-21 15_20_43-.png' '2022-06-02 06_10_50-.png'
'2022-03-24 16_09_55-.png' 323.jpg_large.jpg
'2022-04-09 06_03_34-.png' obi-wan-kenobi-meme.jpg
'2022-04-28 07_52_09-.png' video_image-CiaNV9giv6.jpeg
'2022-06-01 19_13_03-.png'
david@linux-up-skill:/tmp# rm -r images/
david@linux-up-skill:/tmp# tar -xvf test-2-tar-7-11-2022.tar.gz
images/
images/323.jpg_large.jpg
images/2022-04-09 06_03_34-.png
images/video_image-CiaNV9giv6.jpeg
images/2022-04-28 07_52_09-.png
images/2022-03-21 15_20_43-.png
images/2022-06-02 06_10_50-.png
images/obi-wan-kenobi-meme.jpg
images/2022-06-01 19_13_03-.png
images/2022-03-24 16_09_55-.png
david@linux-up-skill:/tmp# rm -r images
david@linux-up-skill:/tmp# tar -xvf test-3-tar-7-11-2022.tar.bz2
images/
images/323.jpg_large.jpg
images/2022-04-09 06_03_34-.png
images/video_image-CiaNV9giv6.jpeg
images/2022-04-28 07_52_09-.png
images/2022-03-21 15_20_43-.png
images/2022-06-02 06_10_50-.png
images/obi-wan-kenobi-meme.jpg
images/2022-06-01 19_13_03-.png
images/2022-03-24 16_09_55-.png

Well that was a great refresher on archiving. Lots of fun!

About the author

David

I am a geek that is passionate about technology and all of the very cool things it can do.

By David

Recent Posts

Categories