Summer Training Program | Day 1 | Linux World | Vimal Daga

Sarath Kumar R S
7 min readMay 23, 2021

Agenda for day 1 :- Basics About Linux And Basics About Python

As we kickstart our Summer Training Program, the first topic or agenda for the day 1 was to learn about basics of Linux and basics of python. As the major part of the leaners were new to this field, we are starting from absolute scratch. We will be leaning about the basic Linux commands, how an OS is interacting with the hardware and the python, the programming language.

A computer is a machine which process information, these informations are at last processed with the help of hardware components. There is RAM, CPU, HARD DISK, NETWORK INTERFACE CARD etc. So to interact with any hardware we need an OS, which connects all the hardwares. So basically a user(or us) use system for one purpose, we want to run some program. Watching video on VLC media player, browsing in the internet using browsers, all these are programmes eventually.

We can interect with the system in two ways, one is a Graphical User Interface(GUI) and Command Line Interface(CLI). GUI is where we use our mouse and click click click. In CLI, we use commands to execute programmes. For example we can open the firefox browser either by clicking on the firefox icon on the Activities tab on Linux, we use mouse to navigate and open the browser, this type of interaction is called GUI method. Likewise we can open the firefox using the CLI with the command called firefox. You may ask where does the firefox command comes from, these come from the program itself. When we are using the GUI method , in background, system is running the command only.

Program is code which is stored in file in some folder in the Harddisk, when we execute or double click , the entire file will transfer from Harddisk to RAM. Then the program become the process.

As we said every program is stored in the hard disk, we have a command to find the location of the program file. In Linux we can use the which command to find this.

which firefox // command to find the file location
/usr/bin/firefox // result

So when we are running a program in the CLI, we can CNTRL + C, to exit the program or stop the program. There is a myth in the market that when we CNTRL + Z, by this also we can stop the program. But it is completely untrue, when we do this the program will be paused and it will go in background process. So if there is any program running in background we can use the command Jobs to see the background programs.

jobs // command to see the background processes

We can use the command fg (foreground) to make the program run again. If there is multiple programmes in the background, we will be able to select the specific ones and run that program only.

jobs
[1]- Stopped python
[2]+ Stopped firefox

This is the background running process currently and if I need to run the python interpreter again, I can use the command fg 1 to run that command again.

(base) sarathkumar@sarathkumar:~/Documents/main/youtubePython/javascript$ fg 1 // command
python
>>>

By this command we will able to restart any previous paused programmes.

So in our local system, if we want to run multiple commands at the same time, we can open a new terminal and do the job there but if we move to a remote system(like AWS cloud, AZURE or Google Cloud), in most of the cases we will only be able to get one terminal interface and if there is a need of running so many commands, we would be forced to stop one program to start another. To overcome this situation, we can combine the command with an ampersand symbol(&) . For example if we need to run firefox and the python interpreter we call it with like firefox & python

firefox & python
[3] 25342
Python 3.7.7 (default, May 7 2020, 21:25:33)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>>

Now am able to run firefox and python in the same terminal. This command will come hand when we advances to more in depth stuff.

We generally create folders in GUI by pressing the right click and by selecting the create new folder option but in CLI, we have a command for that.

mkdir <filename>

I am creating a folder name summerinternship to make it my workspace for this whole workshop.

mkdir summerinternship

This will create a directory in my system. The abbrevation of mkdir is make directory

So, if you wanna see the current directory you are in you can use the command pwd which is print working directory.

pwd
/home/sarathkumar/Music/summerinternship

It will print the current directory, if you wanna navigate through the filesystem, there is a command called cd, which is change directory.

cd <directory name>

This will let you navigate into the directory, if you want to go out from the diretory you can use the command

cd ../

like now, if I do pwd, i am in

pwd
/home/sarathkumar/Music/summerinternship

the summerinternship directory,

(base) :~/Music/summerinternship$ cd ../
(base) :~/Music$ pwd
/home/sarathkumar/Music
(base):~/Music$ cd summerinternship/
(base):~/Music/summerinternship$ pwd
/home/sarathkumar/Music/summerinternship

so by this command you can navigate the file system through terminal.

By this we are concluding the basic of Linux commands for today.

Python

Everything we run on a system is a program, that is the only way we can instruct the system what to do. One of the language which we can use to interact with the system is Python. There are lot of programming languages out there, but for now we will be focusing on the python programming language.

So by far we were running the programs created by someone else and now we will be creating our own programs using python. Before that, we want to install the python interpreter in the system, Linux based OS come with preinstalled python versions, as we are using Linux version, we don’t need to worry about that. If the python is not installed, install that in your system. As we are running our Linux OS on top of windows, we can also install python on windows by a python distribution called Anaconda. It come with a lot of libraries which will be useful for our future lessons.

There are 2 versions of python, python2 and python3. Python3 is now more stable and widely used we will be learning python3. When installing python interpreter will also be installed with that, interpreter help to convert our code to machine understandable code. We can write code in three different methods. Online, Offline and IDE(Integrated Development Environment).

Online is when we are using the interpreter in the terminal itself, it is called REPL(R-Read, E-Evaluate, P-Print, L-Loop). This is invoked when you type the python command in the terminal

python
Python 3.7.7 (default, May 7 2020, 21:25:33)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type “help”, “copyright”, “credits” or “license” for more information.
>>>

Offline is when we create a file and write the code in the file and run the file after that. For the file ,we create a sample.py file with .py extension to tell the system that is is python file.

IDE is where we use a tool like Jupyter, Visual Studio Code etc. in which we can manage everything in a single place.

First thing we gonna learn in python is , how to save a data in a variable. Variable holds a data. For example if we want to save a data 5 in variable in x, we can do that by assigning 5 to x.(Open terminal and run python interpreter)

x=5

I have a data 5 and assigned it to x, this 5 will be stored in RAM and x will hold the address of the data in the RAM. If we want to retrive the data we can just simple type x in the python interpretor.

>>> x=5
>>> x
5

This is how we can store data in a variable.

In other program we need to explicitly, define the data type of the variable, but as python is a dynamic language it will find the type automatically. So to see the data type, we have a method in python called type()

>>> type(x)
<class ‘int’>

That is a Integer data type, let see another example

>>> y=’sarath’
>>> y
‘sarath’
>>> type(y)
<class ‘str’>

Here we can see that the y variable is a String data type. Everything we type inside quotes will be identified as string by the python.

if we exit this terminal and open the terminal, the program we have done will be lost and we need to do all of this again. So we only use online method mainly for debugging purposes or to test the code. For development we want to choose offline method or IDE method to write the code.

let’s see how we can execute the code by offline method. For that we need to create a file. Let’s name it test.py.

x=5
print(x)

we wrote this code in the test.py and if you notice, we used the print() function to print the x. Before we didn’t use the print() function becuase REPL does take care of that, now as a find we need to put the variable inside the print() function to print.

python3 test.py
5

When running a file we need to put the python command before the file. This is how we can run the python file.

So we we need to run a system command inside the file, we can’t just put the system linux command inside the file and hope it will run. If we put that way we will get an error like this

python test.py
5
Traceback (most recent call last):
File “test.py”, line 4, in <module>
date
NameError: name ‘date’ is not defined

We get a NameError saying that it is not defined. So basically we are trying to access a system command inside the file and getting this error. To run any system linux commands we need extra modules, module is a file created by somebody where there will a function we can be used to acheive our result. So here we need an OS module and inside this OS module we need to make use of a system function. Lets see how we can use that.

import os #module imported

x=5

print(x)

print(os.system(‘date’))

Result

python test.py
5
Sun May 23 21:30:12 IST 2021
0

This is how we use modules inside a file.

Here we wind up the first session of our Summer Internship program.

DAY 2 :- https://sarathkumarrs.medium.com/summer-training-program-day-2-linux-world-vimal-daga-91ee7de80fb7

Cheers!

Sarath Kumar R S

--

--

Sarath Kumar R S

Highly enthusiastic individual who is constantly looking solutions by using technology.