Learn Linux with me ✌️

Don't ask why Linux, ask how can I learn Linux - already every company adopted Linux

Where does Linux come from ? someone says its from UNIX , other say it was created by Linus Torvalds. what is the truth? Both are right. Linux comes from Unix and it's kernel was created by Linus Torvalds which he evolved from minix.

To learn more about minix and UNIX - visit linuxjournal.com/article/10754 and also guru99.com/difference-unix-vs-linux.html

What is Linux distribution?

A Linux distribution[a] (often abbreviated as distro) is an operating system made from a software collection that includes the Linux kernel and, often, a package management system. Linux users usually obtain their operating system by downloading one of the Linux distributions, which are available for a wide variety of systems ranging from embedded devices (for example, OpenWrt) and personal computers (for example, Linux Mint) to powerful supercomputers (for example, Rocks Cluster Distribution).

A typical Linux distribution comprises a Linux kernel, GNU tools and libraries, additional software, documentation, a window system (the most common being the X Window System, or, more recently, Wayland), a window manager, and a desktop environment. from - en.wikipedia.org/wiki/Linux_distribution

In Simple term :-

A Linux distro should have GUI(Graphical User Interface) for user to interact with the system and applications with X server/window X, GNU(has utility tools) and a Linux kernel then it can be installed into a hardware which has RAM,Hard Disk, CPU with a display(monitor).

Learning about history of Linux and what is it made of, is good but not as good as knowing how to use it. lets do that now.

Peep into Linux

Anyways One I thing I learnt is that you will be using command line interfaces(CLI) cmds a lot of times, that is preferred once you get the hang of it. This is fun not scary tell that to yourself and embrace the code. ex :

for i in {1..10}; do touch Files_$i; done

image.png

This is cool code.Let me explain what this cmd does , it creates 10 files in the current working directory from where you have run this cmd from,. The cmd touch filename creates a file. Like for example this below command(cmd)

$touch textfile.txt

this creates a empty text file named textfile.txt

What is bash?

First , this line contains bash , that is Bourne again shell (Bourne shell)[should be born of water and spirit to get saved- just kidding] it's a UNIX shell, added into Linux. Bash is a standard Linux shell which is both a command line interpreter and a coding language.

Bash program helps to interact with other programs in the Linux system. It can be considered as a scripting language to interact with the Linux system.

How to remove a created file ?

Just to remove a file we use

rm filename

To remove all the files we just created, we can use this rm cmd which will remove the files.

rm -f Files_*

image.png To check if all the files are deleted , use ls -al cmd , this is similar to dir cmd for windows cmd. It just takes one line of code to create and even smaller ones to delete all the files. How cool is that ?

We are going use Bash to figure out we are using - Operating System here we are using ex. In Ubuntu we use this cmd to see all the OS release information.

cat /etc/*release
$ cat /etc/*release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.6 LTS"
NAME="Ubuntu"
VERSION="18.04.6 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.6 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

Which issue / version

$ cat /etc/*issue*
Ubuntu 18.04.6 LTS \n \l

Ubuntu 18.04.6 LTS

Now run a Utility to Determine the Linux Distribution/get the host details

hostnamectl

$ hostnamectl
   Static hostname: ip-10-0-1-10
         Icon name: computer-vm
           Chassis: vm
        Machine ID: f89138299a734aec9037cb36dcca0fa2
           Boot ID: 23ac266169564ea090de44bbd5c800b6
    Virtualization: xen
  Operating System: Ubuntu 18.04.6 LTS
            Kernel: Linux 5.4.0-1060-aws
      Architecture: x86-64

lsb_release -a

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.6 LTS
Release:        18.04
Codename:       bionic

Some Important Notes In Bash - you can create a variable by simply putting var1="some values" for storing a value. Dont give any space between variables and the assignment or else it will throw error.

Variables : - you don't need to declare a variable explicitly and no need to declare its data type.just create a variable and assign value to it.

var1="Some Values"
echo $var1
Some Values

Here if you see the var1 is storing the value In Bash - single quotes and double quotes act differently unlike other languages you might have seen before. here - single quotes just prints out everything with the quotes and double quotes has some exceptions.

$ var1=$(ls)
$ echo var1
var1
$ echo $var1
Desktop Documents Downloads Music Pictures Public Templates Videos
$ echo "all is not share \ $var1"
all is not share \ Desktop
Documents
Downloads
Music
Pictures
Public
Templates
Videos
$ echo 'all is not share \ $var1'
all is not share \ $var1

Here I'm going to explain what is going on first - what is echo ? it functions same as in windows but has more functionality to it , it's acts like print statement but not the same.

$ $ pwd
/tmp
$ cd ~
$ pwd
/home/cloud_user
$ w
 16:52:24 up  1:09,  1 user,  load average: 0.35, 0.29, 0.21
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
cloud_us pts/0    53.113.58.198    16:51    0.00s  0.03s  0.00s w
$ last
cloud_us pts/0        53.113.58.198    Wed Aug 10 16:51   still logged in
reboot   system boot  4.4.0-1074-aws   Wed Aug 10 15:42   still running

wtmp begins Tue Jan 29 17:24:19 2019
$ w > log.txt
$ last >> log.txt
$ cat log.txt
 16:53:05 up  1:10,  1 user,  load average: 0.33, 0.28, 0.21
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
cloud_us pts/0    53.113.58.198    16:51    1.00s  0.03s  0.00s w
cloud_us pts/0        53.113.58.198   Wed Aug 10 16:51   still logged in
reboot   system boot  4.4.0-1074-aws   Wed Aug 10 15:42   still running

wtmp begins Tue Jan 29 17:24:19 2019
cloud_user@ip-10-0-1-10:~$ ls
Desktop    Downloads  Pictures  scripts    Videos
Documents  Music      Public    Templates
cloud_user@ip-10-0-1-10:~$ ls scripts/
test.sh

One Stepper - reduce steps:

If you seen through the codes , you might have noticed > or >> symbols these are used to create and add the results into the given file.

cat /proc/cpuinfo > cpuinfo.txt

This will create a file cpuinfo.txt and put all the output from that cmd to this file. so this is done in one step. pretty cool right.

How to delete lines from a text file

sed -i '2d' filename

This line will delete 2nd line from the file . use cat cmd to see if there is any text left.

reference for this topic , came from linuxhandbook.com/remove-lines-file