Directory structure in Linux

We are going to see Directory structure in Linux/ Unix and what was the use of those directories.

Directory structure in Linux

/: Root

Root is a parent directory for all the directories and files.

Each and every directories and files will comes under root only.

Only root user only will do any changes in this directory.

For root user /root is the home directory and for others home directory will comes under /home

/home

All the users home directory will be created under /home to store their files. Ex: /home/user

/boot

This directory contains boot loader information.

Boot loader file contains kernel and initramfs image details.

/bin

Contains all the executable binary files which are

commands which we are using in linux/unix.

/sbin

/sbin also contains binary files like same as /bin.

But, this commands are typically used by system administrator.

/etc

Contains configuration files of all the application/programs used in Linux/Unix.

and startup scripts also stored in this location.

/dev

This directory contains all the device files and drivers as well. Like CD Drive, HDD, USB, tty

/tmp

This directory is for temporary use only. All the temps files and directories stored here  which is created by user or system.

Files will be deleted after reboot of the system.

/opt 

Stands for optional.

This directory contains applications installed which all are separate vendor.

/var

Contains all the variable files and logs and  this can be grow in future based on the usage.

Ex:  /var/log/dmesg, /var/log/secure,etc…

/mnt

This will be used to mount devices temporary purpose.

/usr

This directory contains libraries, variables, binaries. /usr/bin directory contains binary files for user level programs and /usr/sbin contains binary files foe system administrator levels.

 

 

Help command and Data Types in Python

In this post we are going to see Help command and Data Types in Python.

Use help along with command which you want need to know more that command.

Here is the example:

Below command will shows the help about print command.

[root@server ~]# python
Python 2.7.5 (default, Aug 2 2016, 04:20:16)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> help ('print')

 

Data types:

  1. Numbers
  2. Strings
  3. Lists
  4. Tuple
  5. Dictionary

Numbers:

Three types of numbers data type available in Python.

Integers: 10

Floating point: 2.1, 3.45

Complex numbers: (4+1J), (3.6 – 5.4a).

If..else.. statement in Bash shell scripting

If..else.. statement in Bash shell scripting

We are going to see if statement in bash shell scripting in Linux/UNIX environment.

If statement is playing the most important role in bash shell scripting and other programming languages. Its working based on condition and we can write another if statement inside of an if statement.

Syntax of If statement:

if [ condition..]
then
  < commands...>
else
  < commands... >
fi

Basic if statement says that, if a condition if valid then, it will execute the single/ set of commands which is comes under then will execute and if a condition not valid then, it will execute the single/ set of commands which comes under else. Finally, it will be ended.

We have some operator which is useful in if statement conditions for validation. Below they are.

Operator Description
 =, ==, -eq  This is to check string/numeric value is equal to another string/ numeric value.
 !=,-ne  This is to check string/numeric value is not equal to another string/ numeric value.
 <=, -le  This is to check string/numeric value is less than or equal to another string/ numeric value.
 >=, -ge  This is to check string/numeric value is greater than or equal to another string/ numeric value.
 <, -lt  This is to check string/numeric value is less than to another string/ numeric value.
 >, -gt  This is to check string/numeric value is greater than to another string/ numeric value.

Example:

[root@server ~]# vi newscript.sh

#!/bin/bash
if [[ $1 -gt "100" ]]
then
 echo "Given values is greater than 100.."
else
 echo "Given value is equal to or less than 100..."
fi

Then provide the execute permission to the script using chmod command.

[root@server ~]# chmod +x newscript.sh

Now will run the script by passing a parameter

[root@server ~]# ./newscript.sh 101
Given values is greater than 100..

 

Basic’s of Python scripting

In this post we are going to see Basic’s of Python scripting.

Use Python command to move to python interpreter like below and using quit() to exit from the interpreter.

and here we used simle print command to print any string.

[root@server ~]# python
Python 2.7.5 (default, Aug 2 2016, 04:20:16)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print ('Hello World')
Hello World
>>> quit()
[root@server ~]#

As you all aware will write bash script in linux/unix. In Python also will create shell script. For that, we need to do simple change in first line like below and even we can create with extension with .sh.

#!/usr/bin/env python

Now we will create our first simple python script to display set of strings. To create this script will use any editor and here i’m going to use vi editor.

[root@server ~]# vi first.py
#!/usr/bin/env python
print "Hello, This is my first script"

use :wq to save and exit from this file and now should provide execute permission using chmod command to run this script.

[root@server ~]# chmod +x first.py

Finally will run the script using ./ like shell scripting.

[root@server ~]# ./first.py
Hello, This is my first script

We successfully created our  first python script.

Python installation in Linux/Unix

In RedHat by default python installed. We are going to see the Python installation in Linux/Unix.

First we have to prepare our system to install Python.

Preparing system:

login as root user, as its a administrator and having full privileges.

Use subscription-manager to know whether you have access to RedHat software repository or not.

[root@server ~]# subscription-manager repos --list-enabled

if you don’t see any repository enabled, than your machine not registered or not having subscription.

Now update using yum command.

[root@server ~]# yum update

Once you executed the above command with valid subscription, all the packages will get updated in your OS.

Now setup your environment:

As you aware already, we are going to use yum to install and check Python package.

Check whether python installed or not using yum.

[root@server ~]# yum list installed | grep python

If the package not installed, use below command to install python.

[root@server ~]# yum install python

above command will ask your confirmation to proceed install. Simply type  and press enter.

Once executed above command, again check whether its installed or not.

[root@server ~]# yum list installed | grep python

Use python  command to run python in interactive mode.

[root@server ~]# python
Python 2.7.5 (default, Aug 2 2016, 04:20:16)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
[root@server ~]#

Finally we installed python in linux.