Basics Linux Concepts
Tags: devops, linux
Published: 2023-08-07 11:58:30


### Linux Distributions


A linux distribution is an open source OS based on linux kernel that package different tools & services like desktop environment, GNU shell utilities, package manager. 


Many organisations & developers have created different linux distributions to suite different needs. Different versions of linux distributions may have some differences in commands.


**Examples**: Ubuntu**,** Debian, CentOS, RHEL, Alpine etc.


### Shell


A shell is an program that helps to interact with OS using various commands & scripts. They take input from the user & run appropriate program to produce output. Some popular shell programs are bash, zsh and fish.


First original shell program was created by Steven Bourne in 1979 for the UNIX. The bash (Bourne Again shell) is free alternative created for GNU project with unix-compatibility.


[IMAGE - A shell prompt root@2f759e6996e9:/ <user>@machine_name:/<current_directory><#|$>]


Linux is case sensitive, so cases must be taken care in everywhere like in commands, file name, directory. Also, unlike Windows were we used back slash to separate directories but linux uses forward slash instead. Using up & down arrow keys we can re-run our commands


### Package Manger


Package managers helps to easily install programs. All package managers contain a database of packages to install. Always remember to update the package manager database before installing a package.


**Debian** based Distribution (Ubuntu, Linux Mint) uses apt (advance package tool) as it’s package manager. Earlier apt-get was used which was replaced with apt, which is more user friendly. DEB (.deb) is the package format for the Debian based distributions.


Common apt commands:

- `apt list` : List all packages from the package database. —installed flag to see installed packages only
- `apt update` : Updates the list of package database.
- `apt install <package-name>`  : Install the given package
- `apt remove <package-name>` : Uninstall/remove the given package

**Redhat & openSuSE**  based Distribution (Fedora, CentOS, RHEL) use dnf in newer version & yum in older versions as it’s package manager. They use RPM (.rpm) package format.


### Linux file system


In Linux (just as with other OSs), files are organized in a tree. In Linux, everything is a file (including processes and directories). The root directory in Linux is just `/`. After that, standard directories include

- `bin` which includes all the binaries for that distro
- `boot` which includes all the files related to booting the system
- `dev` which is short for _devices_ (not development) and includes all the files needed for accessing devices
- `etc` which is short for _editable text configurations_ (not etcetera) and includes all the configuration files
- `home` which where all home directories (Desktop, Documents etc.) for all the users are stored
- `root` which is the home directory of the root user
- `lib` which is where software library dependencies are stored
- `var` which is short for _variable_ and is where we store files that are update frequently (like logs)
- `proc` which is where we store files that represent running processes

### File permissions


To see the permissions details: `ls -l`


![](https://s3.us-west-2.amazonaws.com/secure.notion-static.com/730914ba-2abc-4569-8df4-21bf64d5980e/11.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=AKIAT73L2G45EIPT3X45%2F20230807%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20230807T121216Z&X-Amz-Expires=3600&X-Amz-Signature=2832f21390d2d6ab43a2d259af8f82e1edd6fbb8589c0317cc54585d1987dca8&X-Amz-SignedHeaders=host&x-id=GetObject)


By default every directory has write permission and write permission on a directory means, you can cd into the directory


To change permission: `chmod [who][operator][permssion] ...filename`


Example to give execute permission to a file for the owner: `chmod u+w workflow.sh` . Or provide multiple permission to multiple file in one go: `chmod uo+r+w-x test.py *.sh`