Understanding 'Git', 'Bash', and 'Git Bash'

Written by rajeevbera | Published 2021/11/14
Tech Story Tags: bash-script | bash | git-in-bash | what-is-git-bash | git-bash | learn-to-code | git | programming

TLDRGit Bash is a piece of software that allows you to monitor changes in any group of files. Bash (also known as the "Bourne Again Shell") is nothing but an implementation of Shell. Shell is the outermost layer of the operating system. Bash and Git Bash are two different things, Git and Bash are different. Both shells have different capabilities - both shells have a different set of commands & additional capabilities. Here I will share five different commands to run on the Windows command line and the Git bash.via the TL;DR App

Do you know when you install Git Bash on windows what exactly you are installing? Most of the time, developers think they are only installing Git. But that's not true. Let me repeat it - actually, you are installing Git Bash. These are two different things, Git and Bash.

Git and Bash are two different things.

Git

Git is a piece of software that allows you to monitor changes in any group of files. It's a distributed open-source solution. It is to coordinate work among programmers who are working on source code together during software development with the help of commands.

And now the Bash, it is crucial.

And before you jump to Bash, let's take a moment and try to understand Shell.

Because... both Shell and Bash are connected.

You might have seen a slight protective covering on certain animals like a crab. That small protective covering is known as a Shell.

In the same way, in Computers, The Shell is the outermost layer of the operating system.

It is an environment for the user to interact with the machine.

Here is the detailed aCompilers video that will explain to you what exactly is Git Bash.


Now, let's go back to our original Git Bash.

Bash

Here Bash (also known as the "Bourne Again Shell") is nothing but an implementation of Shell.

Most of the time, developers think Shell is always a command-line interface. Again that's not valid.

In general, operating system shells use either a command-line interface (CLI) or graphical user interface (GUI)

Let's take a few command shell examples in Linux; the two most common Shells are - Bash and KornShell (Korn). And in windows, the two most important command base shells are CMD and Powershell.

All of these shells are different. They have a different set of commands & additional capabilities.

For example, the Linux shell (BASH) has a different command than Windows-based Shell - cmd or Powershell.

Let's take a practical example.

Here I will share five different commands to run on the Windows command line and the Git bash. When executing these commands, you will find out they will only work on the bash shell (and not on the windows command line).

Again the reason - both shells have different capabilities.

Let's dive right into our five bash commands.

PWD

In Shell, PWD is a built-in command. It simply prints the path of your current working directory.

The PWD command is to print the current working directory. It's one of the most fundamental and commonly used commands. When the command is executed, it outputs the full path to the current working directory.

Touch

The touch command is typical in the UNIX/Linux operating system. You can use it for creating, changing, and modifying file timestamps.

You can use the touch command to create an empty file. The touch command generated an empty file. If you do not have any data to save or just need to create a file placeholder, you can use the touch command.

It is mainly used to create an empty file. You can also use the touch command to change and modify the timestamps of a file.

LS

Again the ls command is one of the most popular and commonly used commands in the Linux operating system.

Using the ls command without any options displays files and directories in a basic format, which means you won't be able to see data like file types, sizes, updated dates and times, permissions and links, and so on.

And in case you want to see more details of files, simply use the flag -l with the ls command.

Here in the ls -l, the flag -l is a character, not a number. It will display the file or directory name, size, modified date and time, file or folder owner, and permissions.

But it will not display the hidden files.

You can use the -a (--all) flag in case you want to see the files hidden in the current directory.

Head

A head command is a command-line tool that outputs the first section of files passed over standard input. Head delivers the first ten lines of each file it is given by default.

Pass the filename to the head command to see the first ten lines of a file. Standard output will be used for the first ten lines of the file.

$ head <your file name>

To specify the number of lines to display with the head command, use the -n option and the desired number of lines.

head -n 3 <your file name>

Now it will only show the first three lines of your file.

Tail

The tail command outputs the last section of files passed to it through standard input. It outputs the findings to the standard output. Tail delivers the last ten lines of each file it is given by default.

Pass the name of a file to the tail command to see the last ten lines of it.

The file's final 10 lines will be presented on standard output.

$ tail <your file name>

To specify the number of lines to display, use the -n option followed by the desired number of lines.

$ tail -n 2 <your file name>

Now it will only show the last two lines of your file.


If you need more of such tips and techniques feel free to subscribe to acompilers newsletter.

Now I want to ask you a question and turn it over to you.

Which Shell is your fav? Is it BASH, CMD, or something else?

Let me know by leaving a comment below right now.


This article was first published here.


Written by rajeevbera | I'm a technology enthusiastic. I like to contribute to various projects whenever I get a chance.
Published by HackerNoon on 2021/11/14