Linux CLI Handson 1

Learning CLI fundamentals will help in getting 1000 times more productive .

Why start Linux CLI ?

  1. Usually work using CLI with servers.

    Actual Machines,php work or be it working on cloud, you require ssh to them and boom that gets you into CLI of server.

  2. CLI can do everything a GUI can do and more.

    Although to use services GUI can be used, whenever you work with Linux most common way to interact them is using command line.

    More power to customize your operating system,actual configuration files,

  3. Much faster and productive than GUI for lot of tasks.

    Eg: If you want to append certain string to every name of file in folder and you have let say 10000 file list in single folder with GUI. With automation program it is nightmare correct ? And with CLI, if you know Commands you can go ahead and start doing those things very easily and within couple of seconds,maybe less than a second, you will be done and would be much more productive.

  4. Feels like entered Security Professional, Hacking world.

    Not Just a vibe ,you are actually doing something you know. However friends and colleagues consider it coolest thing when you work in front of friends.

    Overview

    • Linux CLI for Back-end Developer.

    • work /interact with and write simple bash scripts. ( Programming script,xyz shell you use)

    • Common Linux Commands.

    • Common Shell Config Files. (How you can configure shells,how those config files actually work,how to check past commands )

    • Creating small projects

Linux

  • Kernel - Hardware

  • OS Tools - Tools to interact with Hardware

  • Distribution - 3rd party applications

What is Linux

When we talk about any OS or any distribution (install Ubuntu/anything)

Kernel,OS Tool and Distribution.

Kernel is basically piece of software for a piece of software which is responsible for interacting with underlying hardware.

Now you see that you have all those ramps and hard disk and you know all sort of chips inside computer which is interacting with these HW sections.

If there is fault with HW or not.

If you are able to do perform certain action or not.

Linux Kernel

  • Core of any Linux distribution

  • Shared by all Linux distribution

  • Bridge for hardware-software

  • Manages Hardware

  • Eg: try to add 2 numbers.

    How to store number in physical memory is not really

  • Work is handled by Linux Kernel whereas programming languages and other things at top just handle the logic and actual code responsible than Kernel also manages H/W interacting with all H/W is you know.

    When you are installing driver on H/W for that particular H/W only,Linux kernel is able to interact with that particular H/W in that sense.

Tools

  • Use the kernel to interact with H/W.

  • Tool Example - gcc compiler

    Kernel itself cannot work in great way,it is not very useful because it's just saw underlying to talk with H/W.

    So you need tools on top of Kernel to help you as an individual dev, individual person to help you to run certain programs.

  • GNU is collection of these tools.

    Enable you to interact with HW by writing your own code.

  • GNU/Linux is an Linux OS.

Linux shift with Kernel, Collection of Tools GNU shift with Linux in otmrder to make it usable - Linux OS by humans.

Distributions

Layer above tools is distributions.

Package OS with package managers.

Different Goals in Mind:-

Kali Linux

CentOs

Ubuntu

Alpine

  • 2 things are differentiator.

    1.package manager used.

    2.different goal/intent to create.

Kali Linux Box - distribution more oriented towards penetration testing which people went to ethical hacking with bunch of all such tools used and environment ready for themselves might exploit,any sort of tool which is super common in pen testing environment.

Goal of Kali Linux

Alpine's Darker image.

Eg:- 5 MB size

Super small image which consists of just required bits to run an OS has CLI, different Goals for different distribution but all of them really share Linux Kernel.

Basic functionality which enables Linux program to interact with HW,which is shared among all of distributions.

But they might have different packages installed,they might have different package managers.

Underlying concept of management, memory and hard disk knowledge will be applied in every Linux distribution.Thus it is transferable be it CentOS to Kali etc.

Common Linux Commands

Before starting with first command

Set up Ubuntu in VMware > Open Ubuntu OS > Enter Terminal

username@computer eg: root@yashvipc means user root logged in computer name yashvipc

Note: root user has access to everything, you can do everything in system

hash(#) is seen if user is root else $ comes

First Must Command

  • echo (echo back what you say like print function)

      echo Namaste
    

    Namaste reflected back again on screen as answer.

      echo 'Good Morning Mumbai'
    

    Good Morning Mumbai will come then, play printing double quotes using \".

  • clear (when you want to clear out contents on the screen)

  • Ctrl + C (when you don't want to execute what you have entered/edited and you will be back to new line)

Navigating Directories

For GUI, you have all files and folders and you can double click on folder/files to open it.While it is differnet in shell obviously we have to use commands,code only.

" shunyathi sarjan " everything from 0 i personally relate this way with root / which will not have anything under it.

when you want to access/manipulate file its path can be:-

/rootfolder/ubuntu/folder1/.../dummy.txt

  • pwd (print working directory)

  • cd (change directory)

    type 1: cd root (from current directory only you can go there if it exists)

    type 2:cd /root/ubuntu (as specified path)

Lisct files

  • ls (entering in file explorer we get folders/files)

1. green color means unless changed coloring scheme by default used by executable file.

2.based on shell and colors sometime files are different color than folder or like bold white, importand because you will not do cd in file.

  • ls -l

    (best way to know if it is file or directory, compared to coloring or looking at file extension file starts with dash (-) , when it starts with d it is directory )

  • check by doing 1. cd alternatives/ 2. ls -la ypu will check files starts with dash - (Read.me) and something else started with l (definitely it is not exactly directory folder because it starts with d, l could be file directory reference pointing to other file/folder well working as link in lrwxr-xr-x with permissions rwx , rx, r )

cat

to read inside file we use cat software inside shell

Determine OS

we need os -release file located inside etc in root

Read big linux files

in backend we collect logs and when we try to grab from huge text we may get lost:

reading in sort of pages will work so use less instead of using cat,easier to scroll by up and down arrows:

Create directory - mkdir

to create directory(folder)

we go in directory and use mkdir which we want to specify

mkdir subjects

for nested folder structure

mkdir -p folder1/folder2/folder3

navigation within directory

change 2 directoy back directory1/directory2

cd ../..

remove rm

permanently delete files we use rm

to delete folder we remove inside of older first and itself folder also by passing -r with rm

copy cp

cp is good to copy file but likwise rm here we have to use -r for directory folder

move mv

2 usecase:

1.cut and paste

eg:go 1 directory back .. and paste mv

2.renaming also possible even in same directory

3.other eg of cut and paste moving folder in folder and making subfolder

Find Binary Path -which

we use to check command which is actually application located in bin but using this we will know where bin is.