Skip to content

Commit

Permalink
Merge pull request kodekloudhub#3 from K2-KK/master
Browse files Browse the repository at this point in the history
Linux Basic Course Documentation
  • Loading branch information
mmumshad authored Jun 7, 2020
2 parents 7677a01 + 58fb06d commit 9a86112
Show file tree
Hide file tree
Showing 101 changed files with 1,666 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/01-Introduction/01-Introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Introduction

### Course Introduction

- Take me to the [Video Tutorial](https://kodekloud.com/courses/873064/lectures/17080332)

### WAR (Story)

- Take me to the [Video Tutorial](https://kodekloud.com/courses/873064/lectures/17080232)

### Bob's First Day at Work

- Take me to the [Video Tutorial](https://kodekloud.com/courses/873064/lectures/17080284)

### Lab Introduction

- Take me to the [Video Tutorial](https://kodekloud.com/courses/873064/lectures/17317208)
83 changes: 83 additions & 0 deletions docs/02-Working-With-Shell-Part-I/01-Introduction-to-Shell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Working with the shell - I

### Introduction to Shell

- Take me to the [Video Tutorial](https://kodekloud.com/courses/873064/lectures/17074335)

In this section, we will take a look at linux shell in detail.
- We will learn how to use linux commands and understand how to work with files and directories.
- We will also see different ways to get help with linux commands.
- Finally, we will learn about different types of shells used in Linux (particulary focusing on the bash shell)

#### Linux shell

![Shell](../../images/Shell.PNG)

- This command line interface (CLI) will enable you to effectively work on linux laptop/server/virtual machine.
- While the graphical version may see more appealing to the users but can be limited in case of functionality. These is where the Linux command line ccommonly known as **`Linux Shell`** shines.

#### What is a shell?

- Linux shell is a program that allows text based interaction between the user and the operating system, this interaction is carried out by typing commands into the interface and receving the response in the same way.
- The Linux shell is a powerful tool with which you can navigate between different locations within the system, however when you login to the shell the very first directory you were take into is your home directory.

#### The Home Directory

![The-Home-Directory](../../images/The_Home_Directory.JPG)

- A user **`michael`** home directory created under **`/home/michael`**, where **`/home`** is a system created home directory that contains the home directories for almost all users in the linux system.
- The name of the home directory is by default identical to the name of the user, hence **`michael's`** home directory is **`/home/michael`**.
- Remember the home directory is unique for each user. Another user called **`allen`** will have a different home directory which by default created under **`/home/allen`**.

##### Why do we need a home directoy?
- The home directory allows users to store their personal data in the form of files and directories
- Each user in the system gets their own unique home directory with complete access to it (to be able to save, retreive , delete data).
- Think of it as a dedicated locker assign to you in which you can store or retreive items.
- Other users can't access your files and folders with in your home directory (only you can).

**Note** : The representation of the home directory is represented as by the `~ (tilde symbol).`

#### Command Prompt

- You can configure the command prompt to show whatever you want, such as the **`hostname`** , **`date`** or **`time`**.
- It is currently configured to show the current working directory. The **`~` symbol** here represents the home directory

#### Command and Arguments

- To interact with the linux system using the shell, a user has to type in commands
- When a command is run it executes a program to achieve a specific task.
- **`For example`**: The **`echo`** command is used to print a line of text on the screen.
```
$ echo
```
- An argument acts as an input to command
- **`For example`**: To print a **`hello`** message type **`echo hello`** command.
```
$ echo hello
```
- There are several commands that can work without an argument too.
- **`For example`**: Type in the command called **`uptime`**, this is used to print information about how long a system has been running for since the last reboot along with the other information (This command doesn't need an argument)
```
$ uptime
```
- A command can also have options that modify its behaviour in some predetermine way. The option also sometime referred to as a switch or a flag
- **`For example`**: To print a same word `hello` but without a trailing line, use **`echo`** command with **`-n`** flag.
```
$ echo -n hello
```

![Command-and-Arguments](../../images/Command-and-Arguments.PNG)

#### Command Types

Command types in linux can be generally categorized in two types
1. Internal or Built-in Commands
- Internal commands are part of the shell itself. It come bundled with it, there are in total about 30 such commands
- **`For example`**: echo, cd, pwd, set e.t.c.
1. External Commands
- External commands on the other hand are binary programs or scripts which are usually located in distinct files in the system. They either come with pre-install with the distribution package manager or can be created or installed by the user
- **`For Example`**: mv, date, uptime, cp e.t.c.

To determine a command is internal or external, use **`type`** command

![Command-Types](../../images/Command-Types.PNG)
168 changes: 168 additions & 0 deletions docs/02-Working-With-Shell-Part-I/02-Basic-Commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
# Basic Linux Commands

- Take me to the [Video Tutorial](https://kodekloud.com/courses/873064/lectures/17309223)

In this section, we will take a look at basic linux commands
- Specifically related to navigation and creating new files and directories.
- We will do this by completing a simple task using a linux shell.

#### Our goal is to create a directory structure, the top most directory which is **`/home/michael`** which is already created as it as a home directory but everything else underneath has to be created.

![mkdir_cd_working_with_shell_I](../../images/mkdir_cd_working_with_shell_I.PNG)

To print the present working directory. Run **`pwd`** command
```
$ pwd
```

To see the contents of the directory. Run **`ls`** command
```
$ ls
````
To make (or) create a directory. Run **`mkdir`** command
```
$ mkdir Asia
```
To make (or) create multiple directories. Run **`mkdir`** command followed by **`<directory_name1> <directory_name2> .. <directory_nameN>`**
```
$ mkdir Europe Africa America
```
To change a directory from the current directory. Run **`cd <directory_name>`**
```
$ cd Asia
```
To recursively created directories. Run **`mkdir -p <directory_name1>/<sub_directory_of_name1>`**
```
$ mkdir -p India/Mumbai
```
To go back to one directory up. Run **`cd ..`**
```
$ cd ..
```
To go back directly to a home directory of the current user from any location in the system. Run **`cd`**
```
$ cd
```
#### Lets now look at absolute path and relative path
![Absolute_and_relative_path_working_with_shell_I](../../images/Absolute_and_relative_path_working_with_shell_I.PNG)
To change to a directory with absolute path. Run **`cd <directory_path>`**
```
$ cd /home/michael
```
To Change to a directory with relative path. Run **`cd <directoryName>`**
```
$ cd Asia
```
#### Lets now take a look at alternatives to the **`cd`** command
![pushd_popd](../../images/pushd_popd.PNG)
Alternative to the **`cd`** is the **`pushd\popd`** command. To change directory using pushd, run **`pushd <directory_name>`**
```
$ pushd /etc
```
You can change to subdirecties under /etc as many times as you wish
```
$ pushd /var
$ pushd /tmp
$ pwd
/etc/var/tmp
```
To return back to origin directoy(say your home directory), use the **`popd`** command
```
$ popd
```
#### Now lets move on to look some more basic commands in linux. To learn these commands we will make use of the same directory structure as before, however now there are some new files and directories added as shown in the diagram. The goal of this task is to make sure the directory structure looks like the below diagram .
![before_after_commands](../../images/before_after_commands.PNG)
To move file or directory. Run **`mv <source> <destination>`** command
```
$ mv /home/michael/Europe/Morocco /home/michael/Africa/ (Absolute path)
$ mv Europe/Morocco Africa/ (Relative Path)
```
To rename a directory. Run **`mv <oldname> <newname>`** command
```
$ mv Asia/India/Munbai Asia/India/Mumbai
```
To copy a file to a directory. Run **`cp <filename> <destination_directorypath>`** command
```
$ cp Asia/India/Mumbai/City.txt Africa/Egypt/Cairo
```
To delete a file from a directory. Run **`rm /path/<filename>`** command
```
$ rm Europe/UK/London/Tottenham.txt
```
To copy a directory recursively. Run **`cp -r <sourcepath> <destinationPath>`** command
```
$ cp -r Europe/UK Europe/UnitedKingdom
```
To print the content of a file. Run **`cat /path/to/<filename>`** command
```
$cat Asia/India/Mumbai/City.txt
```
To add a content to a file with cat(redirect) . Run **`cat > /path/to/<filename>`** command
```
$ cat > Africa/Egypt/Cairo/City.txt
Cairo
`Type Ctrl + d from keyboard`
```
To create an empty file. Run **`touch /path/to/filename`** command
```
$ touch /home/michael/Asia/China/Country.txt
```
To see the content of a file in a scrollable manner. Run **`more /path/to/filename`** command <-- not recommended for large files
```
$ more new_file.txt
```
To see the content of a file and navigate throught the file. Run **`less /path/to/filename`** command
```
$ less new_file.txt
```
To get the long list of files and directories. Run **`ls -l`** command
```
$ ls -l
```
To list all files including the hidden. Run **`ls -la`** command
```
$ ls -a
```
To list all the files in the order they were modified. Run **`ls -lt`** command
```
$ ls -lt
```
To list all the files form oldest to newest. Run **`ls -ltr`** command
```
$ ls -ltr
```
37 changes: 37 additions & 0 deletions docs/02-Working-With-Shell-Part-I/03-Command-Line-Help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Using command line to get help

- Take me to the [Video Tutorial](https://kodekloud.com/courses/873064/lectures/17309225)

In this section we will learn how to use **`help`** command to get help in command line
- If you are new to using `linux` or `bash shell` or if you are not sure which command does what, there are few commands in bash that can help get started.
- Lets take a look of those

First command is **`whatis`** , this command will displays a one line description of a command does.

**`Syntax: whatis <command>`**

```
$ whatis date
```

Most of the commands internal or external come bundled with **`man pages`** which provides information about the command in detail (with examples, usecases and with command options)

**`Syntax: man <command>`**

```
$ man date
```

Several commands will provide **`-h`** or **`--help`** to provide users with the options and usecases available in a command

```
$ date -h
$ date --help
```

To search through the man page names and descriptions for instances of the keyword use **`apropos`**. This is useful if you want to look for all commands within the system that contains the specifc keyword.

**`Syntax: apropos <keyword>`**
```
$ apropos modpr
```
51 changes: 51 additions & 0 deletions docs/02-Working-With-Shell-Part-I/04-lab-working-with-shell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Lab - Working with shell

- Access Hands-On Labs here [Hands-On-Labs](https://kodekloud.com/courses/873064/lectures/17074343)

1. To check the home directory for a particular user say **`bob`**
```
$ grep bob /etc/passwd | cut -d ":" -f6
```
1. To check the home directory for a particular user using built in shell variables
```
$ echo $HOME
```
1. In the command **`echo Welcome`**, what does the word Welcome represent with respect to the command?
```
$ echo Welcome
- Where Welcome is an argument
```

1. To check **`git`** command type
```
$ type git
```
1. To create a directory
```
$ mkdir /home/bob/birds
```
1. To create directories recursively
```
$ mkdir -p /home/bob/fish/salmon
```
1. Create few more directories
```
$ mkdir -p /home/bob/mammals/elephant
$ mkdir -p /home/bob/mammals/monkey
$ mkdir /home/bob/birds/eagle
$ mkdir -p /home/bob/reptile/snake
$ mkdir -p /home/bob/reptile/frog
$ mkdir -p /home/bob/amphibian/salamander
```
1. To move a directory
```
$ mv /home/bob/reptile/frog /home/bob/amphibian
```
1. To rename a directory
```
$ mv /home/bob/reptile/snake /home/bob/reptile/crocodile
```
1. To delete a directory
```
$ rm -r /home/bob/reptile
```
Loading

0 comments on commit 9a86112

Please sign in to comment.