How to Learn Linux and Git

And how I built a Cloud Storage Clone using them

Syed Mujtaba Jafri
The Startup
5 min readSep 11, 2020

--

I recently started the third year of my undergraduate degree. I did some research regarding which skills are absolutely necessary for a developer to have.

The answer was pretty straightforward, git and linux. Linux is an amazing operating system and git is the best version control system out there.

Fun fact : Git was invented by Linus Torvalds, the man behind Linux. He invented it for development of Linux kernel, with other developers contributing to its initial development.

So, Linux and Git were 2 skills that I felt I wanted to master. Both of them were in my Bucket List of things I wish to learn. I casually procrastinated that I’d learn them. Until I came across Crio.do ….

Coincidentally, they were hosting the September Edition of #IBelieveInDoing. This year their theme was Linux and Git. This felt like killing 2 birds with the same stone !

Image Source: Crio.Do

The first part of the program involved going through their Bytes. They are small learning modules that assist developers to learn the tech skills in an applied way. A Crio Byte includes both documentation and a codebase for a learner to work on.

In this case we had to go through Git Basics, Linux Basics 1 and Linux Basics 2

Linux Basics 1

This byte takes us through the these things :

  1. Getting familiar with the intimidating command line
  2. The basic commands needed to navigate through the Linux Filesystem
  3. Some really interesting facts about linux.
  4. Redirecting input and output.

Here are some very simple commands you could try :

Prints Hello World on the terminal
Prints the present working directory on the terminal
Creates a file called 1.txt in the present working directory

Also, this byte proceeds to explain the Linux Filesystem very nicely.

Image source : https://iotbyhvm.ooo/linux-basic-commands/

Finally, this byte comes to an end with a small excercise in which we perform Data Analysis on huge Hadoop and OpenSSH log files using a script and some simple linux commands. Also, it explained how tasks can be automated on Linux and inspires us to use automation for repetitive tasks.

Git Basics

This byte helps in understanding the basic git workflow. It was a competely practical and hands on approach.

It started with setting up Git / Gitlab for the command line using HTTPS or SSH.

This byte then motivates one to experiment with the basic git commands like git clone, git add, git push, git pull.

It also proceeded to explain what are branches and what are merge conflicts.

Image source: dev.to

At the end of this Byte, I was comfortable with using git from the command line.

Cloud Storage Clone

I believe this is the reason why you are reading this. So, here it goes : )

Image Source: Crio.Do

After completing Linux Basics and Git Basics (which were already practical oriented), it was time for a hands-on project.

My Project can be found here : https://github.com/mujtaba1747/git-autocommit

Also, I’ve open sourced my project so, it’s open to contributions

Here is a short video demonstration of the same :

The idea is pretty simple :

“Linux will monitor for changes in a particular directory, when changes are detected, git commands are triggered to push them to the repository.”

The requirements are :

  1. A Linux system
  2. A github / gitlab or any other git based account. (Tip : Github is most popular and offers Private Repositories which only you can access)
  3. An internet connection (Obviously)

How will Linux actively monitor for changes in a directory ?

Image source : https://askubuntu.com/questions/819265/bash-script-to-monitor-file-change-and-execute-command

Once we detect any changes using inotifywait, we trigger the git commands for pushing the changes to the repository.

This is the bash script used in the project

Now, you might be familiar with the git commands and the cd command. But, I’ve added > /dev/null &> /dev/null at the end of each command

That’s the Black Hole/Void of Linux, nothing that goes there ever returns back. I used it to prevent the script from writing any output to STDOUT and STDERR. In simpler terms, that prevented the script from displaying any output on the terminal as some git commands produce output.

You can read more about it here : STDERR, STDIN and STDOUT and also What is /dev/null in Linux.

23286 is the Process ID of the script. You can find the same by running ps aux | grep “watch.sh”

Also, when launching the script, you have add & (ampersand) to make it run in the background, otherwise the script stops as soon as you exit the command line or press Ctrl + C.

There are few more technical details for which, you can head to my repository on github : https://github.com/mujtaba1747/git-autocommit

So, to summarize

It’s feasible to build a simple service for Linux that’ll watch a directory for changes and push those changes to the cloud in real time. Now, in my case I used a Linux System Call (inotifywait) and git to implement the same.

Something more about Crio.do

The modules are designed in such a manner that even difficult / scary concepts are slowly explained in a simple and lucid manner, along with practical tasks. Apart from their learn by doing approach, the best part about the Bytes was that each part had a curious cats section, which had insightful questions whose answers weren’t present in the Byte. That leaves the learner yearning for more knowledge and thus, he/she looks elsewhere for more. Personally, I found the curious cats section at the end of each milestone really helpful in this Journey.

Also, all the Bytes I mentioned are freely available at : Crio.do

You can sign up for the upcoming #IBelieveInDoing Hacktoberfest Edition at : https://crio.do/IBelieveInDoing/October/

In this 14-days event, you will get started with your first Open Source Pull Request while building your own Crio bytes for the developer community.

#IBelieveInDoing

Keep Learning,

--

--

Syed Mujtaba Jafri
The Startup

Software Engineer @ Trilogy | ICPC ’20 regionalist | Competitive Programmer | LinkedIn : https://bit.ly/3knzm1B