Git Bash (Or Git in Bash)?
Do you know when you install Git Bash on Windows what exactly you are installing? Git or Bash? In this article, learn what you need to know about Git Bash.
Join the DZone community and get the full member experience.Join For Free
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.
Git and Bash are two different things.
Git is a piece of software that allows you to monitor changes in any group of files. It is a distributed open-source solution to coordinate work among programmers working on source code together during software development with the help of commands.
Now, the Bash: it is crucial. 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.
Now, let's go back to our original Git Bash. Here is a detailed video that will explain Git Bash exactly.
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). 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 and 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 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 command is typical in the UNIX/Linux operating system. You can use it for creating, changing, and modifying file timestamps. It is mainly used to create an empty file. If you do not have any data to save or just need to create a file placeholder, you can use 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. This means you won't be able to see data such as file types, sizes, updated dates and times, permissions and links, and so on. In case you want to see more details of files, simply use the flag -l with the
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 -a (--all) flag in case you want to see the files hidden in the current directory.
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 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.
Now I want to ask you a question and turn it over to you. Which Shell is your favorite? Is it BASH, CMD, or something else? Let me know by leaving a comment below right now. If you need more such tips and techniques, feel free to subscribe to aCompilers newsletter.
Opinions expressed by DZone contributors are their own.