Linux and Terminal : Explain like I am 6 👶

Linux and Terminal : Explain like I am 6 👶

·

10 min read

So , let me ask you one thing . How you interact with your computer and most answer would be through the mixture of screen keyboard and a mouse . I guess that's 1000% correct but the things which we do on screen are some graphical methods like If I want to make a new folder names > " newFolder " How can I make it ?

image.png It would be going to be like this . But if I tell you to use the terminal for this problem . Then the second question would be what is terminal , so simply it's a text-based interface used to control a computer (not so graphical but looks cool when using this in a metro -> kinda feel like a hacker🤣 ).

image.png

image.png Open this ! now as you can see the cursor on your screen same is the cursor of terminal is but not that goodlooking .

image.png This shows the screen on which you are right now (the path to be more precise)

So the right clicking and making new folders is the graphical one and using terminal emulator is just the removal of that .

Whenever a user logs in to the system or opens a console window, the kernel runs a new shell instance. The kernel is the heart of any operating system.

So coming next what is Shell ? It's the interface that takes text as input and user can easily operate the operating system through it by these texts . or to be precise A shell is a program that acts as an interface between a user and the kernel. It allows a user to give commands to the kernel and receive responses from it.

Let’s understand the major shells that are available for the Linux environment.

  1. The Bourne Shell (sh) [the first UNIX shell ever] ...

     It gained popularity due to its compact nature and high speeds of operation.
    

2.The GNU Bourne-Again Shell (bash)

    It incorporates useful features from different types of shells in Linux such as Korn 
   shell and C shell.

    It allows us to automatically recall previously used commands and edit them with 
    help of arrow keys, unlike the Bourne shell.
  1. The C Shell (csh)

       It was developed to include useful programming features like in-built support for       
       arithmetic operations and a syntax similar to the C programming language.
    
  2. The Korn Shell (ksh)

     The Korn shell is essentially a superset of the Bourne shell.
    

Thats more than enough for you to know about shells Now we are going further with the Bash i.e Bourne Shell Again Shell

So for downloading bash in your system you can simply download git and we get the bash terminal within it . %[git-scm.com/downloads]

So open the bash shell

image.png this is how it looks like now as it was told that this is a curson and a pointer to so moving from one directory to another , means double clicking a folder .

We can use "cd" here means change directory . let's have a look

image.png So here we got our cursor to the desktop by double clicking the folder . Now I have to make a folder so which means I have to make a directory , making it short " mkdir " yes , that's it type this in the shell with a name of the folder

image.png

Ok now if I want to get the list of the apps or directory which are inside the folders , we can simply do " ls ". right now we dont have anything in our pro folder . For adding files to it we can use touch command , like touch sa.cpp which will create a c++ file name sa.

Lets do it

image.png

Now as we filled something in the folder we can use the ls command

image.png

It's true ig 🚀💖 yes for using that back button we can simply do cd .. so go back to your init by cd ..

and do the ls command

image.png

image.png

just in between to make you more familiar with the linux one ..

Now the next task if we are making our terminal with something else like python3 simply type python3 and you are ready with a python compiler on the terminal

Now I want to check wether git is running or not ..... type git

image.png

and you will get this .. One question is in my mind that how this thing callled bash is able to identify where this git is .. Answer for this is simply type "where git"

image.png

and you got this with some hands on this too.!!!!

Internall its doing this same thing but where the helll they find the adress toooooooooo?

Environment variables !!!! "a variable whose value is set outside the program, typically through functionality built into the operating system or microservice."

I got introduced to this when in my first year I was not able to run cpp file on VS code and the mingw path was not on environment variables which lead to missing of mingw file ......

A command "echo" simply means display ~ Sorry , not mentioned this above .....

now there is one environemnt variable called path ..... whats in it ? lets check

echo $PATH ~ display whats there in path

image.png

these are the path where that shell checks if those command are present here or not

: divides the path .....means : after this it's a new path

ls -a helps us to show the hidden files with .starting names

image.png

So let's go more into commands :

  1. pwd : Print working directory -> name suggests what it does ..

image.png

  1. ls : lists all the item present in the directory ( . shows all file .... "ls -a" shows hidden files too "ls -l" shows files with more description .

  2. cat : This command is used to print the content of the file and also we can write within that file too.

let's go with an example :

image.png by making cat > we can make changes to a file and by changing each line it gets saved automatically to it !

for ending this process we have to do "ctrl+c"

and now have made changes to this file .

image.png

now when I dont enter > this the content of that file would be displayed on the screen !

now , If I dont have any file and I do this cat > two.txt then the file would be created and we have to make changes to it !

image.png

Now I am having an extra file for that ..... Let's merge this to a single file ..

cat hello.txt two.txt > third.txt

image.png

That's how it works !!

now ">" this symbol simply means to share the output !! and as we have discussed "echo" is the print of terminal

now , if I do echo "Hello ">hello.txt which simply means that I want to print this in this given file ...

image.png

end();

  1. man : Now I forgot what echo does or what cat does ..... then what a man would do "A Real Man " he would guide me with it ...

  2. tr : It simply means translate .. like the file of hello.txt includes "Hello " , now I want to make it HELLO ..... what would I do I would simply say to the machine that cat hello.txt means take the output of this | this would tell to machine that there are more operations to be done tr a-z A-Z :: now this is the function which we are ecpecting to be changed and we have to store this to another file for that >upper.txt

5 head : shows the first 10 lines by default or you can change it by head -n 4 , this will simply give top 4 lines of that file

6 . tail : same as head but from below !

  1. find : It simply finds that file which is required here

image.png

now if I want to find only directories inside a folder then what we will do ?

find . -type d

image.png

for files replace d with f

image.png

now if we want to search a named file !!!

find . -type d -name "NewAgain.txt"

image.png

and we got the file

if you dont remember the name but some keys of that like two.txt , you forgot two now you can search for *.txt , all the .txt folder would be displayed!!!

Simple na :)

Now if we are finding some stuffs we need to have the knowledge of file permission too!

So we have three types of permissions : Read r Write w Execute x

Three types of people who are going to use them : Person/Individual u Group -> Entity g Others o now I want to change permissions for NewAgain file !!

image.png

now for changing mod we use a command chmod and we will change the permissions to it (the new again file )

image.png

Now the commands which I gave to them by rwx , we can do this in binary format also !!

Like chmod 777

now this allotted u=wrx , g =wrx, o=wrx So the first digit is for user the second one for groups and the third one for the others and coming to numbers

4 stands for read 2 stands for write and 1 for execute !!!

So if you want to have read and execute permissions then 555

image.png

If you want to know who you are just type whoami

image.png I exist!!

Now if you want to change the owner

You can use chown root NewAgain.txt if that doesn't work then add sudo in front as we dont have access to the root owner

We have a find command for finding the files, but what if we want to search for a string then we have grep in rescue !!

8 . grep : command-line tool used to search for a string of characters in a specified file..

image.png

shows the version of grep command .. and now as we have made names.txt at the beginning .

Now we can simply search Saksham using grep (remember that this grep is a case sensitive )

grep "Saksham" names.txt

would be the command to be used

image.png

Now what if we know a particular word of a string like , let me change my name to Saksham Awasthi and we have only saksham ! how to do that then

simply grep -w "Saksham" names.txt

image.png got the whole word !!

now if you want to remove this case sensitive feature then simply add -i tag to it ; like grep -i "saksham" names.txt

image.png

Thats how this tag works!

Now if I want to know the line number of that ! -n tag is there to rescue

image.png

Now we can use these all tag in a single command by -win and if I want to search my name on all the .txt files then the command which I am going to use will be

grep -win "Saksham" ./*.txt/

image.png

got each line where I mentioned my name !!

9 . History : Moving to the next ... as the keyword simply tells what is it !!

now simply type the histroy keyword in the terminal and you will get all the cringe things you were doing on that , cause I found mine too 🤣

image.png

Now we can make a pipe too , in which we can chose the history which includes this part only for that then

history | grep "ls"

lets see what happens here >

image.png

got this !!

image.png

10 : regex command : This is the task to you to google it and let yourself know about it ... Seeing your attention :)

11: uname : Kernel name

image.png gives the hostname

image.png

this would look like cat hello.txt | tr a-z A-Z >upper.txt

image.png

Simple :) So it's a pipe or a tunnel which we done just now . as someone else's file output is someone else''s input !!

That's it with the basic of Linux and commands <3

Â