Learn about the command line.
Tags: beginners, devtips, codenewbie, productivity
Published: 2020-03-16 00:24:09

If you've ever been intimidated by the command line or curious about it and how to use the command line, this article will help you get started and comfortable.

##What you will learn.
* What is the command line?
* Why is the command line important?
* Basic command and navigation.
* Integration with git and github.

###What is the command line?
The command line (commonly also referred to as CLI, Terminal, bash, or shell) is an application for typing commands directly to a computer's operating system.It lets you interact and give instructions to your computer

According to wikipedia:
>A command-line interface processes commands to a computer program in the form of lines of text

It is basically a tool that takes a command in form of normal text and processes the instruction. You can use it in place of GUI(the normal interface we use everyday on our computer). Don't worry, you will understand more when will get to its basic command. Every operating system comes with a pre-install command line.
You can navigate or open the command line on your PC by:
-Using the search bar on Windows, input "cmd" then open the command prompt app
-On Mac PC, click on the spotlight icon(looks like a search bar) then search for terminal
-If on Linux then you will probably find it in **Applications -> System or Applications -> Utilities**.

However, the command line i personally use is [Git Bash](https://git-scm.com/downloads) which i prefer to the pre-installed ones.
###Why is the command line important?
You probably thinking right now!
![alt text](https://res.cloudinary.com/petrepan/image/upload/v1583882205/giphy_pqiyv9.gif "I don't need this")
The command line is one of the most important applications on your computer, It helps us automate our tasks very easily. If you ever want to be a coder or work in a tech team as a designer, product manager, or other tech role, you'll have a big advantage if you're already comfortable with basic commands. But anyone who uses a computer will benefit from becoming comfortable with this essential tool!
It helps us to perform many tasks quicker and can be much easier to automate and do remotely.
Now let's get to the work!.
###Basic command
You don't need to know all the commands to start using the command line. Let's get started with some basic ones.
####print working directory
```
$ pwd
```
print working directory represented by 'pwd' returns the directory or folder or current path you're working on.
```
$ pwd
/c/Users/petrepan
```
This shows that i'm currently in `petrepan` folder which also is in the `Users` folder on my computer.
####make directory
Make directory is used to create a new folder. So you make use of `mkdir` coupled with the 'name of the folder'.
```
$ mkdir terminaltips
```
So i just created a folder called terminaltips
####change directory
Change directory is used to switch into a directory, you can use the “cd” command (where "cd" stands for "change directory"). So, i created (`mkdir`) a directory called terminaltips. I can navigate into the directory by using 'cd'
```
$ cd terminaltips
```
####cd ..
```
$ cd ..
```
To move up one directory or to go to a previous one, use `cd ..`. make sure there's a space between the keyword `cd` and the two dots.
####touch
```
$ touch project.txt
```
`touch` creates a new file inside a folder. It takes in a file name as an argument, and then creates a new empty file in the current working directory. Here we used touch to create a new file named index.html.
####Move files
This is used to move a file into another folder, use `mv` with the name of the file and then the name of the folder. Here we move the file 'project.txt' into another folder called project.
```
$ mv project.txt project
```
####Copy files
You might want to copy your file instead of moving it, you can follow the same process with the `mv` command. But this time, you make use of the `cp` command.
```
$ cp project.txt project
```
####RM -R
`rm -r` is used to delete a folder, `rm`(remove). To delete a folder, you need to be in its parent directory, not inside the folder itself. Here we deleted a folder called terminaltips. 
```
$ rm -r terminaltips
```
####RM
`rm`(remove) command deletes files. Here we remove the file project.txt. The above one is used for deleting folders while this one is used for deleting files.
```
$ rm project.txt
```
####List
The command `ls` lists all files and folders in the working directory. working directory means your current directory. You can check your current with the command `pwd` we learnt above.
```
$ ls
projects   terminaltips   index.html   words.txt
```
`ls -a` command can be used to list all contents including hidden files and directory.
####echo
This command is used to add a text to a file. By using the `echo` command followed by the text(in quotation) and then `>`, followed by the filename.
```
$ echo "This is a text. We're adding it to a file." > project.txt
```
We added the quotated text to the text file called project.txt
####grep
Most times this is used in big project cos it lets you look for a certain text within a file. The usage for this is less obvious when you're not working on a big code project.
```
$ grep adding project.txt
```
We just searched for where the word 'adding' exist in terminaltip.txt. It will return the lines that contain the content you seek for.
```
$ grep adding project.txt
We're adding it to a file.
```
With this commands, you can easily navigate between files and folders in your computer.
###Integration with git and github
So this is just going to be a little project on how we can use the command line in conjunction with git and github.
Git is a version control system that helps us keep track of our files on our computer. This can help us to monitor and manage different changes made on our files.whereas
Github is a website that helps us to host our folders or repositories online.
Both git and github are useful tools for developers.
Here we are going to create a folder on github and clone it to our computer. Make sure you install and configure [Git](https://git-scm.com/downloads). And also sign up on [github](github.com) if you don't have an account.

*Step one: Create a folder on your computer.
*Step two: Navigate into the folder
*Step three: Create a repository on github.
*Step four: Clone your repository.
*Step five: Create a file

####Step one: Create a folder on your computer.
Open your command line and make a folder with the `mkdir` command. Here we created a folder called 'project'.
```
$ mkdir project
```
####Step two: Navigate into the folder
Let's navigate into the 'project' folder with `cd`.
```
$ cd project
``` 
####Step three: Create a repository on github
Login into your github and create a repository, let's call it git-testing. Now you have something like this
![alt text](https://res.cloudinary.com/petrepan/image/upload/v1584312371/petrepan_git-testing_il1jqx.png)
####Step four: Clone your repository
Click the green button at the right hand side that says "Clone or download" and copy the link.
Now go back to your terminal and clone the github repository to your computer with `git clone`
```
$ git clone https://github.com/petrepan/git-testing.git
```
####Step five: Create a file
Now that you have the 'git-testing' folder on your computer, we can create a file with the `touch` command. Let's create two files. 
```
$ touch index.html
```
```
$ touch app.css
```

Voila!! That's the basics of using the command line. We can even go further to check the list of files in the 'git-testing' folder with the `ls` command.
Lastly, use the `clear` command to clean up your command line when the command gets too much.
###Conclusion
There's a lot more we can do with the command line especially when the project gets overwhelming. It makes our life easier.

So feel free to explore and learn more about the command line, git and github.

Thanks for reading! Don't forget to leave a comment and a like.