How to Compress and Extract Files Using the tar Command on Linux

Compress an Entire Directory or a Single File

Use the following command to compress an entire directory or a single file on Linux. It’ll also compress every other directory inside a directory you specify–in other words, it works recursively.

tar -czvf name-of-archive.tar.gz /path/to/directory-or-file

Here’s what those switches actually mean:

  • -c: Create an archive.
  • -z: Compress the archive with gzip.
  • -v: Display progress in the terminal while creating the archive, also known as “verbose” mode. The v is always optional in these commands, but it’s helpful.
  • -f: Allows you to specify the filename of the archive.

Continue reading

Setting file dates from EXIF data for JPEG files

ExifTool (which is free software written by Phil Harvey) lets you set the last modified date of the file system to the date the picture was taken, which is stored in the EXIF data of the JPEG file by virtually any digital camera. Simply create a folder with all the JPEGs and run this command:

exiftool "-DateTimeOriginal>FileModifyDate" myjpgfolder

This also allows you to set the file date to the exact second. Typically memory cards for digital cameras are formatted as FAT which truncates creation times to even seconds, as it’s one bit short for storing the time more precisely than at 2 second intervals.

Hello Diary!

Hello Everyone,

This blog is going to be list of articles which I find very useful when I look for them. Often I find some articles/tutorials/piece of code very useful, I bookmark them, but later either the link does not work or I can’t find what I am looking for. In this Code Diary blog I am going to publish these articles, so that I personally can access them easily.

I will also follow the tutorial step by step, make sure that the tutorial works, so if you have any difficulties feel free to leave a comment, I will try to reply as soon as possible. I hope the blog will be useful for you.

Happy coding!