Linux Basics (Shell Commands)
Tags: linux
Published: 2021-12-25 04:55:28

## About Linux

Linux was created by a Software Engineer named [Linus Torvalds](https://en.wikipedia.org/wiki/Linus_Torvalds). Linux is a _“family of open source Unix-like operating systems based on the_ [_Linux kernel_](https://en.wikipedia.org/wiki/Linux_kernel)_” — _[_Wikipedia_](https://en.wikipedia.org/wiki/Linux). The first Linux kernel was written in 1991. The Software layers used to describe the Linux structure are as follows:

**.**  **The kernel**  — Runs the hardware and allocates resources.   
**.**  **The shell** (Which I will focus on here) — Where you type commands into the CLI (Command Line Interface).  
**.**  **Applications layer**  — Where programs run, such as [GCC](https://en.wikipedia.org/wiki/GNU_Compiler_Collection) (Gnu Compiler Collection) and [vi](https://en.wikipedia.org/wiki/Vi) (a popular text editor).

_Linux Operating System hierarchy_

![Image of Linux system hierarchy](https://cdn-images-1.medium.com/max/642/1*LgKCfBbHzcFapeNnAEKx0g.jpeg)

## Linux file system

In most operating systems including Linux, directories (aka. folders) are structured in a hierarchical tree-like way. This keeps our files and folders organized. The root directory is labeled as a forward slash ‘/’ character, all other directories sit below the root. When you first log in you will be taken to the home directory.

_Linux file system tree_

![Image of Linux file tree layout](https://cdn-images-1.medium.com/max/831/1*Z0EG48pmJzZfN_K6GqV6GQ.jpeg)

## Basic commands

The following is a list of some of the most common Linux shell commands _(each command will be followed by_ _/$ which is just an example of being in the root directory of the terminal)_:

`/$ ls` - List storage. This command will list the contents of the current directory you're in.

`/$ cd` - Change directory. This will bring you to your home directrory. To navigate up a level use cd.., back a directory cd -, to root cd /, or if you have it follow a path it will bring you to that directory, for example ` cd home/jay/documents`.

`/$ pwd` - Print working directory. Outputs the path of the current working directory starting from the root. Example output /home/jay/photos .

`/$ mkdir` - Make directory. Short for make directrory, will create a new directory when followed up with a name that the user types (must be all lower case), for example mkdir myfiles.

`/$ touch` - Mainly used to create new empty files touch myfile.

`/$ rm` - Remove. This command is mainly used for removing files and directories. Use this with caution as there is no trash bin in Linux.

`/$ mv` - Move. Moves file(s) from one directory to another mv file1.txt file2.txt, also can be used to rename a file mv name newname.

`/$ echo` - Outputs lines the user types in front of it as string arguments echo "Hello World!". This command is usually used in shell scripts and batch files.

`/$ grep` - Global Regualr Expression Print. My favorite, this is a very useful command that can be used to search for string charcaters in a file. When it finds the characters you're searching for it will output the result grep "hello" greeting.txt.

_Linux video resources:_ [_Linux: a short documentary_](https://www.youtube.com/watch?v=aurDHyL7bTA&feature=emb_title)_,_ [_What is Linux_](https://www.youtube.com/watch?v=zA3vmx0GaO8)