> For the complete documentation index, see [llms.txt](https://olb.gitbook.io/linux-essentials-certification/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://olb.gitbook.io/linux-essentials-certification/2.finding_your_way_on_linux/2.1-command_line_basics.md).

# 2.1 Command Line Basics

**Weight 3**\
Key knowledge areas

* Basic shell
* Command line syntax
* Variables
* Quoting

Partial list of the used files, terms and utilities

* Bash
* echo
* history
* PATH environment variable
* export
* type

***

## Lesson 1

**Shell**:

* program for text based communication between user and OS
* interpret text into instructions for Linux
* Bash (Bourne-Again shell)
* C shell (csh)
* Korn shell (ksh)
* Z shell (zsh)

Prompt: `username@hostname current_directory shell_type`

* `hostname` is also a command
* shell\_type is `#` for root or `$` for user

### Command line structure

`command [options] [arguments]` eg: `ls -l /home`

**options** also called **flags** `-` for short form `--` for long form `$ ls -al` `$ ls -a -l` `$ ls --all --format=long`

### Command behavior types

#### Internal

Around 30 commands (cd, pwd, set, export) use `type` to know

#### External

Binary programs or scripts Use `PATH` to find the binary file

### Quoting

#### Double Quotes " "

* everything is normal character except `$` `\` `` ` ``
* space is no more argument separator
* `$ echo "I am $USER" => I am tom`

#### Single Quotes ' '

* everything is normal character
* `$ echo 'I am $USER' => I am $USER`

#### Escape Character : \\

* disable special characters like `$`
* `$ echo \$USER =>$USER`

### Commands used in this lesson

* **bash** The most popular shell on Linux computers.
* **echo** Output text on the terminal.
* **ls** List the contents of a directory.
* **type** Show how a specific command is executed.
* **touch** Create an empty file or update an existing file’s modification date.
* **hostname** Show or change a system’s hostname.

## Lesson 2

### Local variables

* current shell process only
* not inherited by sub processes

### Environment variables

* shell session and sub processes

### Manipulating variables

* use `=` to assign `variable=hello`
* use `` ` `` to assign a command result `variable=` `` `pwd` ``
* use `echo $variable` to display
* use `unset` to empty `unset variable`
* use `export variable` for environment variable

### PATH

* `PATH=$PATH:new_directory` add new path
* `which` command show the command path
* order of elements in `PATH`is lookup order

### Command used in Lesson 2

* **env** Display the current environment.
* **echo** Output text.
* **export** Make local variables available to subprocesses.
* **unset** Remove a variable
