Understanding Linux and Its Commands
Tags: linux, opensource, operatingsystem, tutorial
Published: 2022-09-10 21:03:39

Operating systems are the core of daily applications, managing the communication between the hardware and software. Operating systems include Windows, iOS, Mac OS, and Linux.

This article will discuss what the Linux operating system is, why anybody should be interested in the Linux operating system, and, more importantly, basic commands we can run with Linux.

## What is Linux?
[Linux](https://www.linux.org/) is an entire family of open-source Unix operating systems based on the [Linux Kernel](https://en.wikipedia.org/wiki/Linux_kernel). The Linux kernel was created to work with various hardware, from phones and computers to cars. It manages the hardware resources and software packages.

## Prerequisites 
To get started with this article, we must have the following:
- A Command line interface (CLI) is installed on the computer. For Windows users, it is advisable to use GIT Bash to run the commands. To download GIT Bash, check out this [page](https://git-scm.com/downloads)
- An IDE, download the Visual Studio code IDE [here](https://code.visualstudio.com/)

## Why Linux?
Understanding that there are other operating systems, Linux, in particular, has been gaining popularity in recent years because of the following reasons:
- The Linux operating system is open-source. Open-source infers that the software is available to the public for studying, modification and distribution. 
- Many people use the Linux operating system, so we can easily leverage this community support and outsource solutions to our problems.
- Linux supports a wide range of hardware like phones, laptops, servers, etc.
- Linux effectively automates processes.
## Basic Linux Commands

This article section will discuss some of the CLI commands available to us with Linux. Open up our Git Bash CLI and run the following commands.

- **pwd:** This command tells us the path of the directory we are currently in.
![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662836928921_1.png)

- **ls**:: Use this command to list all the files and directories in our current directory.
![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662836977338_2.png)

- **mkdir**: Use the Linux command to create a new directory or folder. We run this command to create a folder or directory named `linux_practice`.
![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662836991225_3.png)


In the image above, we create a directory and list all the files and directories with the `ls` command. 

- **cd** : Use this command to navigate through different directories. This `cd` command requires the [absolute](https://www.techopedia.com/definition/5817/absolute-path#:~:text=An%20absolute%20path%20refers%20to,absolute%20pathname%20or%20full%20path.) or [relative path](https://desktop.arcgis.com/en/arcmap/10.6/tools/supplement/pathnames-explained-absolute-relative-unc-and-url.htm#:~:text=A%20relative%20path%20refers%20to,moving%20up%20in%20the%20hierarchy.) of the directory we want to change to.
![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662837014335_4.png)


In the screenshot above, we can see that our current directory has changed to `linux_practice`.

We can use some shortcuts to navigate through directories using the `cd` command. The shortcuts are listed below:

    - The `cd` or `cd ~` command will navigate the user to their home directory.
    - The `cd ..` command will move the user up one directory, so if the user was in the `/first/second`, running the `cd ..` command moves the user to the `/first` directory.
    - The `cd -` command navigates the user to the previous directory.


- **touch:** Use the command to create empty files in Linux. The `touch` command creates a file on our machine that we can open and update in our IDE.
![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662837040071_5.png)

![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662838490790_Screenshot+564.png)
![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662838490806_Screenshot+565.png)
![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662838490818_Screenshot+566.png)

- **cp:** Use this command to copy files into a directory or copy directories from one location to another. 

To copy files into a directory, we specify what file we want to copy and the directory we want to copy the file into, alongside the `cp` command.

![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662837068048_6.png)


In the screenshot above, we copied the `practice_file` from the `linux_practice` directory and pasted it into the `linux_test` directory.

We use the `ls` command to verify that we successfully copied and pasted the file.

To copy directories, we add the `-rvfp` parameter.

- **rm:** Use this command to delete files and directories in a directory.
    - To delete files or directories, we specify the file or directory we want to delete alongside the `rm` command. To delete directories, add the `-rf` parameter.


- To delete files
![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662837126335_7.png)


To delete directories

![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662837138956_8.png)

- **cat:** Use this Linux command to display the contents of a file.
![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662838825860_12.png)

- **locate:** Use this  command to locate a file on the Linux system. To make the search case insensitive, use the -i flag.


- **grep**: Use this command to search through a text file.
![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662837178675_9.png)

- **head:**  Displays the first ten lines of a file.
- **tail**: Displays the last ten lines of a file.
- **sed:** Use this command to replace texts in a file.
![Linux Command](https://paper-attachments.dropbox.com/s_37205680422B410F66EAA7F32A7180ACABE85F4235E85C7F675FA3061DCB1EA4_1662837499266_10.png)

- **find:** Use this command to find files or a directory’s path.
- **sudo:** Use this command to execute commands usually executed by the root user.

## Conclusion
This article discussed what Linux is, why we should care about the Linux operating system, and, more importantly, how commands we can execute in Linux.

## Resources
The resources below can be helpful:
- [Linux Tutorials](https://www.linux.org/forums/linux-beginner-tutorials.123/)
- [Difference Between Absolute and Relative Path](http://www.differencebetween.net/technology/difference-between-absolute-and-relative-path/#:~:text=In%20simple%20words%2C%20an%20absolute,directory%20you%20are%20working%20on.)