Thursday, 10 May 2018

100 Linux Commands Video Tutorial Every Administrator Should Learn

For All the Videos

       arch - print machine hardware name (same as uname -m)
       arp - manipulate the system ARP cache
       at, batch, atq, atrm - queue, examine or delete jobs for later execution
       gawk - pattern scanning and processing language
       bc - An arbitrary precision calculator language
       blkid - locate/print block device attributes
       cal - display a calendar
       cat - concatenate files and print on the standard output
       bash,  :,  .,  [, alias, bg, bind, break, builtin, caller, cd, command, compgen,
       chage - change user password expiry information
       chattr - change file attributes on a Linux file system
       chgrp - change group ownership
       chmod - change file mode bits
       chown - change file owner and group
       cp - copy files and directories
       cpio - copy files to and from archives
       crontab - maintains crontab files for individual users
       curl - transfer a URL
       cut - remove sections from each line of files
       date - print or set the system date and time
       dd - convert and copy a file
       df - report file system disk space usage
       diff - compare files line by line
       dig - DNS lookup utility
       du - estimate file space usage
       expr - evaluate expressions
       fdisk - manipulate disk partition table
       find - search for files in a directory hierarchy
       firewall-cmd - firewalld command line client
       free - Display amount of free and used memory in the system
       grep, egrep, fgrep - print lines matching a pattern
       head - output the first part of files
       bash,  :,  .,  [, alias, bg, bind, break, builtin, caller, cd, command, compgen,
       hostname - show or set the system's host name
       id - print real and effective user and group IDs
       ifconfig - configure a network interface
       ip - show / manipulate routing, devices, policy routing and tunnels
       kill - terminate a process
       last, lastb - show listing of last logged in users
       less - opposite of more
       ln - make links between files
       ls - list directory contents
       lsof - list open files
       lspci - list all PCI devices
       man - an interface to the on-line reference manuals
       mkdir - make directories
       mount - mount a filesystem
       mv - move (rename) files
       netstat  - Print network connections, routing tables, interface statistics, mas‐
       nice - run a program with modified scheduling priority
       nslookup - query Internet name servers interactively
       passwd - update user's authentication tokens
       pam_tally2 - The login counter (tallying) module
       paste - merge lines of files
       ping - send ICMP ECHO_REQUEST to network hosts
       perl - The Perl 5 language interpreter
       pgrep, pkill - look up or signal processes based on name and other attributes
       ps - report a snapshot of the current processes.
       pwd - print name of current/working directory
       halt, poweroff, reboot - Halt, power-off or reboot the machine
       rm - remove files or directories
       rpm - RPM Package Manager
       rsync - a fast, versatile, remote (and local) file-copying tool
       sed - stream editor for filtering and transforming text
       sort - sort lines of text files
       ss - another utility to investigate sockets
       sysctl - configure kernel parameters at runtime
       tail - output the last part of files
       tar - manual page for tar 1.26
       top - display Linux processes
       touch - change file timestamps
       tr - translate or delete characters
       uname - print system information
       uniq - report or omit repeated lines
       uptime - Tell how long the system has been running.
       useradd - create a new user or update default new user information
       vim - Vi IMproved, a programmers text editor
       vmstat - Report virtual memory statistics
       w - Show who is logged on and what they are doing.
       watch - execute a program periodically, showing output fullscreen
       wc - print newline, word, and byte counts for each file
       Wget - The non-interactive network downloader.
       yum - Yellowdog Updater Modified

Arithmetic Operators | Shell Scripting Beginners Tutorial-34

Friday, 18 August 2017

Installing and Configuring Linux LVM with Multipath simple Steps

Configuring Multipath Linux LVM Steps.

#To Install Multipath supportable RPM's
yum install -y device-mapper-multipath*

#Generate Sample Multipath Configuration
mpathconf --enable --user_friendly_names y

#Start Multipathd Services
systemctl start multipathd.service

#To Check Netapp SAN LUN Disks and Paths
sanlun lun show -p

# Configure Multipath Alias
vim /etc/multipath.conf

#check the Status of Configured Alias reflected 
multipath -v2

# List Created Disk Paths
ls -al /dev/mapper/

#Create Linux LVm Partition
fdisk /dev/mapper/DATA-DISK

#Add Mapping to Partition
kpartx -a /dev/mapper/DATA-DISK

#Create Physical Volume
pvcreate /dev/mapper/DATA-DISKp1

#Create Volume Group
vgcreate ATE-PROD /dev/mpath/DATA-DISKp1 /dev/mpath/DATA-DISKp1

#Create LV with 100% Free Space
lvcreate -n U03 -l 100%FREE DATAVG

#File System Creation in Newly Created LVM
mkfs -t ext3 /dev/DATAVG/U03

#Mount Permanently using fstab Entry
vi /etc/fstab

/dev/DATAVG/U03  /u03    ext3    defaults        1 2

Monday, 31 July 2017

Java Update Guide Centos 7 / RHEL 7

Java is a programming language and computing platform first released by Sun Microsystems in 1995. There are lots of applications and websites that will not work unless you have Java installed, and more are created every day. Java is fast, secure, and reliable. From laptops to data centers, game consoles to scientific supercomputers, cell phones to the Internet, Java is everywhere!

# java -version
java version "1.7.0_141"
OpenJDK Runtime Environment (rhel- u141-b02)
OpenJDK 64-Bit Server VM (build 24.141-b02, mixed mode)

32 Bit Java Download Link
# wget --no-cookies --no-check-certificate --header "Cookie:; oraclelicense=accept-securebackup-cookie" ""

64 Java Download Linux
# wget --no-cookies --no-check-certificate --header "Cookie:; oraclelicense=accept-securebackup-cookie" ""

# du -sh jdk-8u144-linux-x64.tar.gz
177M    jdk-8u144-linux-x64.tar.gz
# tar -xvf jdk-8u144-linux-x64.tar.gz

[root@Arkit-Serv java]# update-alternatives --install /usr/bin/java java /opt/java/jdk1.8.0_144/bin/java 100
[root@Arkit-Serv java]# update-alternatives --config java

There are 3 programs which provide 'java'.

  Selection    Command
*+ 1           java-1.7.0-openjdk.x86_64 (/usr/lib/jvm/java-1.7.0-openjdk-
   2           /usr/java/jdk1.8.0_144/jre/bin/java
   3           /opt/java/jdk1.8.0_144/bin/java

Enter to keep the current selection[+], or type selection number: 3

[root@Arkit-Serv java]# export JAVA_HOME=/opt/java/jdk1.8.0_144/
[root@Arkit-Serv java]# export JRE_HOME=/opt/java/jdk1.8.0_144/jre
[root@Arkit-Serv java]# export PATH=$PATH:/opt/java/jdk1.8.0_144/bin:/opt/java/jdk1.8.0_144/jre/bin

# java -version
java version "1.8.0_144"
Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

That's it Java Updated.

Monday, 24 July 2017

Free Python Programming E-Books Download

Download and Learn 3 Python Programming Books Completely Free

  1. Drive Into Python – Written by Mark Pilgrim Download Now
  2. Learning Python – Written by Fabrizio Romano Download Now
  3. Python Cook Book – Written by Sebastian Download Now

Of course you have to fill Details and Click Download you will get to your Email Directly.

Just Spending one Minute of time instead of paying a few dollars of money

Best of Luck Learn Python Programming Freely with your own learning curve

Thursday, 20 July 2017

Failed To Load SELINUX policy. Freezing error after reboot on Centos 7/RHEL7?

system[1]: Failed to load SELinux policy. Freezing error after reboot on Centos 7/RHEL7?

 Most of the time you will get this error "while resetting the root password". That means you are not correctly reset the root password (or) mismatch words in the "touch /.autorelabel" command.

"touch /.autorelabel" -->  create an hidden file under the slash which means SELinux will automatically relabel the SELinux policy when server is booting

SELinux Load Error

1) Reboot your machine
2) Loading boot menu then press key to stop the boot menu, edit(press 'e') kernel line.

Change String SELInux

3) Goto "linux16" word and append the word "selinux=0".
4) reboot the server.

That't it.

Installing nagios core got error - Resolution

While installing nagios core got error make all command on RHEL7/centos 7:

while installing nagios core on RHEL7  got the issue that is "(cd angularjs && unzip -u,/bin/sh: unzip: command not found". The error occur after enter the command make all . On my server have already installed gcc so the error was coming from some other dependency requirement.

[root@serverx nagios-4.1.1]# make all
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -o nagiostats nagiostats.c  -lm  ../lib/libnagios.a
make[1]: Leaving directory `/tmp/nagios-4.1.1/base'
cd ./cgi && make
make[1]: Entering directory `/tmp/nagios-4.1.1/cgi'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/tmp/nagios-4.1.1/cgi'
cd ./html && make
make[1]: Entering directory `/tmp/nagios-4.1.1/html'
(cd angularjs && unzip -u
/bin/sh: unzip: command not found
make[1]: * [all] Error 127
make[1]: Leaving directory `/tmp/nagios-4.1.1/html'
make: * [all] Error 2
[root@serverx nagios-4.1.1]#

Observed the above error i.e "unzip command not fund", Installed the unzip package by following below command

# yum install -y unzip

After installed the unzip package, rerun the configure command issue has been resolved.

That's it.

Saturday, 25 February 2017

RHEL7 installation Kickstart File

I have made Kickstart (Auto Answer File) Using Kcikstart configuration generator tool with LVM partitioning included

[root@ArkIT ~]#cat ks.cfg
#platform=x86, AMD64, or Intel EM64T
# Install OS instead of upgrade
# Keyboard layouts
keyboard 'us'# Reboot after installation
# Root password
rootpw --iscrypted $1$tS7oWXXF$X.HS5njtcfPpxHgW9pFtX.
# System timezone
timezone Africa/Abidjan
# Use network installation
url --url=""
# System language
lang en_US
# Firewall configuration
firewall --disabled
# Network information
network  --bootproto=dhcp --device=eth0
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
# Run the Setup Agent on first boot
firstboot --enable
# SELinux configuration
selinux --disabled

# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
# Partition clearing information
clearpart --all --initlabel
volgroup rhel --pesize=4096 PV0
part PV0 --fstype=lvmpv --ondisk=sda --size=50000
part /boot --fstype=xfs --size=500
logvol / --vgname=rhel --name=root --fstype=xfs --size=10000
logvol /var --vgname=rhel --name=var --fstype=xfs --size=8000
logvol swap --vgname=rhel --name=swap --fstype=swap --size=8000
logvol /home --vgname=rhel --name=home --fstype=xfs --size=7000
logvol /usr --vgname=rhel --name=usr --fstype=xfs --size=7000



useradd ravi
echo password | passwd ravi

Thursday, 19 January 2017

A Major Difference Between RHEL 6 vs RHEL 7 Here you go

RHEL 7 vs RHEL 6

Red Hat Enterprise Linux 7 is an Light weight and minimized Operating system. RHEL 7 changes are huge effect to enterprise.

Let's see what changed in RHEL 7 as per administration prospective.

  • First one is Anaconda Installer Completely new.
  • Grub version updated from 0.97 to Grub 2 fast booting
  • Procedure of bypassing root password at booting process completely different than RHEL 6/5 
  • There is no SysV Initd in RHEL 7 it's an new Systemd
  • Run Levels are changed to Targets.
  • Default file system in RHEL 7 is XFS. XFS file system supports 550TB of each partition size in 64-bit.
  • Directories /bin /sbin /lib and /lib64 are moved under /usr/
  • Network Interface Names are changed from eth0 to
  • New concept to create multiple profiles top of one Ethernet card, No need of changing IP addresses and settings every time when you connect different networks, simply activate different profile.
  • GNOME version changed from 2 to 3
  • No classic registration system, completely changed to Red Hat subscription Manager
  • Default database is MariaDB instead of MySQL
  • Cluster Manager has been changed to Pacemaker and Corosync
  • Ifconfig command is deprecated, replaced with ip command
  •  User Identification Numbers (UID's) changed from 500 to 1000, which means when you create new normal user in RHEL 7 will get UID from 1000 to 65534
  • locate command is changed to mlocate
  •  yum commands are changed little bit

Feature Name RHEL 6  RHEL 7
Default File System Ext4 XFS
Kernel Version 2.6.xx 3.10.xx
Release Name Santiago Maipo
Gnome Version GNOME 2 GNOME 3.8
KDE Version 4.6 4.1
Release Date 10-Nov-10 10-Jun-14
NFS Version NFS 4 NFS 4.1. NFS V2 is deprecated in RHEL 7
Samba Version 3.6 4.4
Default Database MariaDB MySQL
Cluster Resource Manager Rgmanager Pacemaker
Network Grouping Team Driver will support multiple types of Teaming methods called Active-Backup, Load-balancing and Broadcase Bonding can be done as Active-Backup, XOR, IEEE and Loac Balancing
KDUMP RHEL 7 can be supported up to 3TB Kdump does't support with large RAM Size
Boot Loader Grub 2
Grub 0.97
File System Check xfs_replair
- Inode blockmap checks
-Inode allocation map checks
-Inode size check
-Directory check
-Path Name check
-Link count check
-Freemap check
-Super block check
-Inode check. Block and size check
--Directory Structure check
-Directory Link Check
-reference count check
-Group Summary Check
Process ID Systemd (1) Initd (1)
Port Security Firewalld instead of iptables. Iptables can also support with RHEL 7, but we can't use both of them at the same time. Firewall will not allow any port until and unless you enabled it. iptables by default service port is enabled when service is switched on.
Boot Time 40 Sec 20 Sec
File System Size EXT4 16TB with XFS 100TB XFS 500TB with EXT4 16TB
Processor Architecture 32Bit and 64Bit Only 64Bit.
Network Configuration Tool steup nmtui
Hostname Config File /etc/sysconfig/network /etc/hostname No need to edit hostname file to write permanent hostname simply use hostnamectl command
Interface Name eth0 ens33xxx
Managing Services service sshd start
service sshd restart
chkconfig sshd on
systemctl start sshd.service
systemctl restart sshd.service
systemctl enable sshd.service
System Logs /var/log/ /var/log
Run Levels runlevel 0 - Power Off
runlevel 1 - Single User Mode
runlevel 2 - Multi User without Networking
runlevel 3 - Multi User CLI
runlevel 4 - Not USed
runlevel 5 - GUI Mode
runlevel 6 - Restart
There is no run levels in RHEL 6. Run levels are called as targets
UID Information Normal User UID will start from 500 to 65534
System Users UID will start from 1 to 499
Normal User UID start from 1000 - 65534
System Users UID will start from 1 to 999

Because Services are increased compare to RHEL 6
By Pass Root Password Prompt append 1 or s or init=/bin/bash to Kernel command line Append rd.break or init=/bin/bash to kernel command line
Rebooting and Poweroff poweroff - init 0
reboot - init 6
systemctl poweroff
systemctl reboot
YUM Commands yum groupinstall
yum groupinfo
yum group install
yum group info

Thanks, please provide your valuable feedback on the same.

Thursday, 15 September 2016

ReviewBoard Complete Installation Guide Ubuntu

ReviewBoard Installation and configuration to review the developers code. 

# apt-get install openssh-server
# service ssh restart
# apt-get install python-setuptools
# apt-get install python-setuptools
# easy_install -U setuptools
# apt-get install python-dev
# apt-get install memcached
# easy_install python-memcached
# apt-get install patch
# easy_install ReviewBoard
# sudo apt-get install python-cffi
# sudo apt-get install build-essential autoconf libtool pkg-config python-opengl python-imaging python-pyrex python-pyside.qtopengl idle-python2.7 qt4-dev-tools qt4-designer libqtgui4 libqtcore4 libqt4-xml libqt4-test libqt4-script libqt4-network libqt4-dbus python-qt4 python-qt4-gl libgle3 python-dev libffi-dev
# easy_install ReviewBoard
# sudo apt-get install zlib1g-dev libxml2-dev libxslt1-dev
# easy_install ReviewBoard
# apt-get install libpq-dev python-dev libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libffi-dev
# easy_install ReviewBoard
# easy_install mysql-python
# apt-get install python-mysqldb
# easy_install mysql-python
# apt-get install mysql-server
# apt-get install python-mysqldb
# easy_install mysql-python
# apt-get install libmysqlclient-dev
# easy_install mysql-python
# easy_install psycopg2

# apt-get install libpq-dev
# easy_install psycopg2
# apt-get install cvs
# apt-get install git-core
# easy_install mercurial
# apt-get install pip
# easy_install pip
# pip install p4python
# easy_install mercurial
# apt-get install subversion python-svn
# apt-get install python-subvertpy
# easy_install subvertpy
# easy_install django-storages
# easy_install django-storage-swift
# easy_install nose Sphinx
# apt-get install apache*
# service apache2 restart
# service apache2 status
# vi /etc/mysql/my.cnf
# mysql -u root -p
# rb-site install /var/www/html/reviewboard1
# chown -R www-data /var/www/html/reviewboard1/htdocs/media/uploaded
# chown -R www-data /var/www/html/reviewboard1/htdocs/media/ext
# chown -R www-data /var/www/html/reviewboard1/htdocs/static/ext
# chown -R www-data /var/www/html/reviewboard1/data
# cd /var/www/html/
# rm -rf index.html reviewboard
# cp reviewboard1/conf/apache-wsgi.conf /etc/apache2/sites-available/
# cp reviewboard1/conf/apache-wsgi.conf /etc/apache2/sites-enabled/
# cd /etc/apache2/sites-enabled/
# rm -rf 000-default.conf
# cd sites-available/
# rm -rf 000-default.conf default-ssl.conf
# apt-get install libapache2-mod-wsgi

# service apache2 restart
# service apache2 status
# cp /var/www/html/reviewboard1/conf/apache-wsgi.conf reviewboard1.conf .
# cp /var/www/html/reviewboard1/conf/apache-wsgi.conf reviewboard1.conf
# rm -rf apache-wsgi.conf
# cd ../sites-enabled
# ln -s ../sites-available/reviewboard1.conf .

# vi /etc/apache2/sites-enabled/reviewboard1.conf
ServerName localhost

# service apache2 restart
# service apache2 status

Command Summary execute as it is installation of ReviewBoard will be done.

Saturday, 7 May 2016

reset rhel7 root password

In the RHCSA examination they ask to reset the root password, In this article we are going to learn how to reset rhel7 root user password.

Whenever you type user password incorrectly it will shown an above error. 

 Immediate After Right side of the corner there is a power button Click on that power button and Click on Restart Server. Server will restart.

 While restarting of server you have to press any key to stop the OS booting process yet the stage of Kernel. As shown in above screen shot kernel line will stop. Then Press 'e'

After pressing key 'e' then kernel lines will be edited. As shown in below screenshot
if you see there is a line start with "linux16" go to that line press 'END' key to go last of the line. In END of the line write "rd.break console=tty1" (without quotations). Then Press CTRL+x

Server will go to Single user mode. As shown in above screen shot.
In this mode /sysroot file system bill be mounted as ReadOnly. We have to make /sysroot as ReadWrite then only we can able to change the password.

Changing password means we are indirectly writing the encrypted password in /etc/shadow file.
To mount /sysroot file system in ReadWrite run below command
# mount -o remount,rw /sysroot

Now change to root using below command
#chroot /sysroot

Now prompt will be changed to Shell.
# passwd 
New Password: redhat
Retype Password: redhat

Now root password has been changed to 'redhat'. If you reboot the server will not come back. in RHEL7 by default SELinux is in enforced mode we have to relabel the SELinux inorder to bring back the server in Normal Stage.

To Relabel the SELinux run below command
# touch /.autorelabel

Now type exit exit two times System will be restart
 sh-4.2# exit
switch_root:/# exit

That's it now RHEL7 server will be back after that type username: root and Password: redhat.

Successfully rested RHEL7 root user password.

Thursday, 31 March 2016


DHCP Server :: Dynamic Host Control protocol

Port Number 67
Package: dhcp*
service : dhcpd.service
config file: /etc/dhcp/dhcpd.conf

[root@server7 ~]# yum install dhcp*
Loaded plugins: langpacks
Package 12:dhcp-common-4.2.5-27.el7.x86_64 already installed and latest version
Package 12:dhcp-libs-4.2.5-27.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package dhcp.x86_64 12:4.2.5-27.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

 Package                          Arch                               Version                                       Repository                            Size
 dhcp                             x86_64                             12:4.2.5-27.el7                               rhel_dvd                             506 k

Transaction Summary
Install  1 Package

Total download size: 506 k
Installed size: 1.4 M
Is this ok [y/d/N]: y
Downloading packages:
dhcp-4.2.5-27.el7.x86_64.rpm                                                                                                           | 506 kB  00:00:00    
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 12:dhcp-4.2.5-27.el7.x86_64                                                                                                                1/1
  Verifying  : 12:dhcp-4.2.5-27.el7.x86_64                                                                                                                1/1

  dhcp.x86_64 12:4.2.5-27.el7                                                                                                                                

[root@server7 ~]# systemctl enable dhcpd.service
ln -s '/usr/lib/systemd/system/dhcpd.service' '/etc/systemd/system/'
[root@server7 ~]# systemctl start dhcpd.service
[root@server7 ~]# firewall-cmd --permanent --add-service=dhcp
[root@server7 ~]# firewall-cmd --reload
[root@server7 ~]# cp /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example /etc/dhcp/dhcpd.conf
cp: overwrite ‘/etc/dhcp/dhcpd.conf’? y
[root@server7 ~]# vim /etc/dhcp/dhcpd.conf

## Default Line Number 48 ###
# A slightly different configuration for an internal subnet.
subnet netmask {
  option domain-name-servers;
  option domain-name "";
  option routers;
  option broadcast-address;
  default-lease-time 600;
  max-lease-time 7200;

:wq! (Save & Exit)

#systemctl restart dhcpd.service

Tuesday, 22 March 2016

providing remote block storage - RHEL 7 / Centos 7

iSCSI, which stands for Internet Small Computer System Interface, works on top of the Transport Control Protocol (TCP) and allows the SCSI command to be sent end-to-end over local-area networks (LANs), wide-area networks (WANs) or the Internet.

  • Create one LVM
  • Convert that LVM into LUN using iSCSI Software
  • Map Converted LUN to initiator and use it as a local HDD to initiator

Creating LVM

[root@server4 ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xab08db42.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): Hit Enter
Using default response p
Partition number (1-4, default 1):
Hit Enter 
First sector (2048-20971519, default 2048):Hit Enter
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +5G
Partition 1 of type Linux and of size 5 GiB is set

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@server4 ~]# partprobe /dev/vdb

[root@server4 ~]# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created
[root@server4 ~]# vgcreate vgiscsi /dev/vdb1
  Volume group "vgiscsi" successfully created
[root@server4 ~]# lvcreate -l 100%FREE -n lviscsi vgiscsi
  Logical volume "lviscsi" created

[root@server4 ~]# lvs
  LV      VG      Attr       LSize Pool Origin Data%  Move Log Cpy%Sync Convert
  lviscsi vgiscsi -wi-a----- 5.00g             

[root@server4 ~]# yum install targetcli*

[root@server4 ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> ls
o- / ......................................................................................................................... [...]
  o- backstores ........................................ [...]
  | o- block ........................... [Storage Objects: 0]
  | o- fileio ............................... [Storage Objects: 0]
  | o- pscsi ............................... [Storage Objects: 0]
  | o- ramdisk ............................ [Storage Objects: 0]
  o- iscsi ........................................ [Targets: 0]
  o- loopback ..................................... [Targets: 0]
/> /backstores/block create iscsilun /dev/vgiscsi/lviscsi
Created block storage object iscsilun using /dev/vgiscsi/lviscsi.
/> ls
o- / ...................................................... [...]
  o- backstores ........................................... [...]
  | o- block ............................... [Storage Objects: 1]
  | | o- iscsilun ...[/dev/vgiscsi/lviscsi (5.0GiB) write-thru deactivated]
  | o- fileio ................................. [Storage Objects: 0]
  | o- pscsi ............................... [Storage Objects: 0]
  | o- ramdisk ............................ [Storage Objects: 0]
  o- iscsi ........................................ [Targets: 0]
  o- loopback ..................................... [Targets: 0]
/> /iscsi create
Created target
Created TPG 1.

/> ls
o- / ..................................................... [...]
  o- backstores .......................................... [...]
  | o- block .............................. [Storage Objects: 1]
  | | o- iscsilun .......... [/dev/vgiscsi/lviscsi (5.0GiB) write-thru deactivated]
  | o- fileio ............................. [Storage Objects: 0]
  | o- pscsi .............................. [Storage Objects: 0]
  | o- ramdisk ............................ [Storage Objects: 0]
  o- iscsi ........................................ [Targets: 1]
  | o- ................. [TPGs: 1]
  |   o- tpg1 ........................... [no-gen-acls, no-auth]
  |     o- acls ...................................... [ACLs: 0]
  |     o- luns ...................................... [LUNs: 0]
  |     o- portals ................................ [Portals: 0]
  o- loopback ...................................... [Targets: 0]

GO TO Client side and collect the iqn number

[root@desktop4 ~]# yum install iscsi*
Loaded plugins: langpacks
rhel_dvd                                                                                                                       | 4.1 kB  00:00:00    
(1/2): rhel_dvd/group_gz                                                                                                       | 134 kB  00:00:00    
(2/2): rhel_dvd/primary_db                                                                                                     | 3.4 MB  00:00:00    
Package iscsi-initiator-utils- already installed and latest version
Package iscsi-initiator-utils-iscsiuio- already installed and latest version
Nothing to do

[root@desktop4 ~]# cat /etc/iscsi/initiatorname.iscsi
[root@desktop4 ~]# systemctl enable iscsid.service
ln -s '/usr/lib/systemd/system/iscsid.service' '/etc/systemd/system/'
[root@desktop4 ~]# systemctl start iscsid.service

Come Back to the Server and Map LUN to Initiator

/> /iscsi/ create
Created Node ACL for
/> iscsi/ create /backstores/block/iscsilun
Created LUN 0.
Created LUN 0->0 mapping in node ACL

/> /iscsi/ create
Using default IP port 3260
Created network portal

/> saveconfig
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

Press CTRL + D

[root@server4 ~]# firewall-cmd --permanent --add-port=3260/tcp
[root@server4 ~]# firewall-cmd --reload

Go To Client and Connect the Mapped LUN

[root@desktop4 ~]# iscsiadm -m discovery -t st -p,1
[root@desktop4 ~]# iscsiadm -m node -T -p -l
Logging in to [iface: default, target:, portal:,3260] (multiple)
Login to [iface: default, target:, portal:,3260] successful.

[root@desktop4 ~]# fdisk -l /dev/sda

Disk /dev/sda: 5364 MB, 5364514816 bytes, 10477568 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes

[root@desktop4 ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x2e115ccc.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (8192-10477567, default 8192):
Using default value 8192
Last sector, +sectors or +size{K,M,G} (8192-10477567, default 10477567):
Using default value 10477567
Partition 1 of type Linux and of size 5 GiB is set

Command (m for help): p

Disk /dev/sda: 5364 MB, 5364514816 bytes, 10477568 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
Disk label type: dos
Disk identifier: 0x2e115ccc

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1            8192    10477567     5234688   83  Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@desktop4 ~]# partprobe /dev/sda
[root@desktop4 ~]# mkfs.ext4 /dev/sda1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=1024 blocks
327680 inodes, 1308672 blocks
65433 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1340080128
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736

Allocating group tables: done                           
Writing inode tables: done                           
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

[root@desktop4 ~]# mkdir /ravi

[root@desktop4 ~]# vim /etc/fstab
[root@desktop4 ~]# cat /etc/fstab |grep sda
/dev/sda1    /ravi    ext4    _netdev    0 0
[root@desktop4 ~]# mount -a
[root@desktop4 ~]# df -h |grep ravi
/dev/sda1       4.8G   20M  4.6G   1% /ravi


Monday, 14 March 2016

Searching file content in Linux/Unix

1. Check Grep version
grep -V

2. Search single word in single file / multifles
grep <string> *

3. Search Multiple words in single file / multiple files
grep -E 'word1|word2'

4. Seach text which is not maching to string
grep -v "String" fileName

5. Print the matching string and its before lines
grep ens33 -A 4

6. Print the matching string and its after lines and its around lines
grep enss33 -B 4
grep ens33 -C 4

7. Search a string Recursively
grep -r <string> <fileName>

8. Grep the string with highlighted in color
grep --color=auto <string> <file Name>
export GREP_COLOR='1;30;43'

9. display the lines which does not matches all the given strings
grep -v -e "a" -e "b" -e "c" filename.txt

10. Get the count of given string from file
grep -c <string> filename

11. Search for files which are matching to the given string
grep -l this demo*

12. Beginning of line (^) using cap symble
grep "^Nov 10" messages.1

13. End of the line ( $) using dollar symble
grep "terminating.$" messages

? The preceding item is optional and matched at most once.
* The preceding item will be matched zero or more times.
+ The preceding item will be matched one or more times.
{n} The preceding item is matched exactly n times.
{n,} The preceding item is matched n or more times.
{,m} The preceding item is matched at most m times.
{n,m} The preceding item is matched at least n times, but not more than m times.

Few examples about grep command..

Comment one grep command below in comment section....

Sunday, 13 March 2016

Managing Files and Directories - Linux

                In Linux all are files only. Based on the type we identify the files. In this article we are going to see how to create, list, copy, move and delete the files and directories. 

1. Creating files and Directories
2. Listing Files and Directories
3. Copying Files and Directories
4. Moving files and directories
5. Deleting Files and Directories

Create empty files 

To create an empty files, we have to use touch command

                           touch is a standard Unix command-line interface program which is used to update the access date and / or modification date of a file or directory. In its default usage, it is the equivalent of creating or opening a file and saving it without any change to the file contents. Touch eliminates the unnecessary steps of opening the file, saving the file, and closing the file again. Instead it simply updates the dates associated with the file or directory. An updated access or modification date can be important for a variety of other programs such as backup utilities or the make command-line interface programming utility. Typically these types of programs are only concerned with files which have been created or modified after the program was last run.
[root@server1 touch]# touch file
[root@server1 touch]# ls -l
total 0
-rw-r--r--. 1 root root 0 Mar 13 07:01 file

[root@server1 touch]# touch file1 file2 file3 file4
[root@server1 touch]# ls -l
total 0
-rw-r--r--. 1 root root 0 Mar 13 07:08 file1
-rw-r--r--. 1 root root 0 Mar 13 07:08 file2
-rw-r--r--. 1 root root 0 Mar 13 07:08 file3
-rw-r--r--. 1 root root 0 Mar 13 07:08 file4

[root@server1 touch]# touch ravi{1..10}.txt
[root@server1 touch]# ls -l
total 0
-rw-r--r--. 1 root root 0 Mar 13 07:09 ravi10.txt
-rw-r--r--. 1 root root 0 Mar 13 07:09 ravi1.txt
-rw-r--r--. 1 root root 0 Mar 13 07:09 ravi2.txt
-rw-r--r--. 1 root root 0 Mar 13 07:09 ravi3.txt
-rw-r--r--. 1 root root 0 Mar 13 07:09 ravi4.txt
-rw-r--r--. 1 root root 0 Mar 13 07:09 ravi5.txt
-rw-r--r--. 1 root root 0 Mar 13 07:09 ravi6.txt
-rw-r--r--. 1 root root 0 Mar 13 07:09 ravi7.txt
-rw-r--r--. 1 root root 0 Mar 13 07:09 ravi8.txt
-rw-r--r--. 1 root root 0 Mar 13 07:09 ravi9.txt

Create file using cat command

                          The program cat is a standard Unix utility that reads files sequentially, writing them to standard output. The name is derived from its function to catenate/concatenate and list files.

[root@server1 cat]# cat > filebycat
This file is created by cat command
[root@server1 cat]# cat filebycat
This file is created by cat command

Creating Directories

mkdir (make directory) command in the Unix, DOS and OS/2 and MS windows and other programs is used to make a new directory.

[root@server1 mkdir]# mkdir testdir
[root@server1 mkdir]# mkdir dirtest dir1
[root@server1 mkdir]# ls -l
total 0
drwxr-xr-x. 2 root root 6 Mar 13 07:16 dir1
drwxr-xr-x. 2 root root 6 Mar 13 07:16 dirtest
drwxr-xr-x. 2 root root 6 Mar 13 07:16 testdir

Listing files and directories

                        To list the files and directories we have to use 'ls' command. 'ls' command will list files and directories current directory, by providing the remote directory path will list all files and directories on that remote directory.

ls command with 25 practical examples

ls <Path>

[root@server1 mkdir]# ls
dir1  dirtest  testdir
[root@server1 mkdir]# ls -ltr
total 0
drwxr-xr-x. 2 root root 6 Mar 13 07:16 testdir
drwxr-xr-x. 2 root root 6 Mar 13 07:16 dirtest
drwxr-xr-x. 2 root root 6 Mar 13 07:16 dir1
[root@server1 mkdir]# ls -k
dir1  dirtest  testdir

Copy files and directories

                         cp is a UNIX command for copying files and directories. The command has three principal modes of operation, expressed by the types of arguments presented to the program for copying a file to another file, one or more files to a directory, or for copying entire directories to another directory.

we have to use -r option along with cp command to copy the directories.

cp <SourcePath> <DestinationPath>

[root@server1 ~]# cp file1 dir1/
[root@server1 ~]# cp testdir dir1/
cp: omitting directory ‘testdir’
[root@server1 ~]# cp -r testdir dir1/

Moving files and directories

                   mv (short for move) is a Unix command that moves one or more files or directories from one place to another. If both filenames are on the same filesystem, this results in a simple file rename; otherwise the file content is copied to the new location and the old file is removed. Using mv requires the user to have write permission for the directories the file will move between. This is because mv changes the content of both directories (i.e., the source and the target) involved in the move. When using the mv command on files located on the same filesystem, the file's timestamp is not updated.

mv <SourcePath> <DestinatioPath>

[root@server1 ~]# mv file3.txt /tmp/
mv: overwrite ‘/tmp/file3.txt’? y

[root@server1 ~]# mv dir1/ /tmp/
mv: overwrite ‘/tmp/dir1’? y
mv: cannot move ‘dir1/’ to ‘/tmp/dir1’: File exists

Deleting Files and Directories

               rm (short for remove) is a basic UNIX command used to remove objects such as files, directories, device nodes, symbolic links, and so on from the filesystem. To be more precise, rm removes references to objects from the filesystem, where those objects might have had multiple references (for example, a file with two different names), and the objects themselves are discarded only when all references have been removed and no programs still have open handles to the objects.

[root@server1 ~]# ls
anaconda-ks.cfg  file1       file5.txt  file8.txt             mkdir  tech1  testdir   touch
cat              file10.txt  file6.txt  file9.txt             pipe   tech2  testdir1
dir1             file4.txt   file7.txt  initial-setup-ks.cfg  Pipe   tech3  testdir2

[root@server1 ~]# rm -rf file*

[root@server1 ~]# ls
anaconda-ks.cfg  dir1                  mkdir  Pipe   tech2  testdir   testdir2
cat              initial-setup-ks.cfg  pipe   tech1  tech3  testdir1  touch

We have a different file types in Linux we will discuss about few file types:

1. Regular Files (-)

we can create files using #touch command

[root@server1 ~]# ls -l |grep ^-
-rw-------. 1 root root 1292 Jan 19 23:14 anaconda-ks.cfg
-rw-r--r--. 1 root root 1343 Jan 19 23:15 initial-setup-ks.cfg
-rw-r--r--. 1 root root   31 Mar 13 04:54 Pipe

2. Directory Files (d)

Directories will start with d character we can search the directories using below command

[root@server1 ~]# ls -l /* |grep ^d
drwxr-xr-x. 2 root root       26 Jan 19 23:08 grub
drwxr-xr-x. 6 root root      104 Jan 19 23:14 grub2
drwxr-xr-x. 2 root root         200 Mar 13 01:16 block

3. Block File (b)

These files are hardware files most of them are present in /dev
find block file in Linux

ls -l /dev/* |grep ^b

[root@server1 ~]# ls -l /dev/* |grep ^b
brw-rw----. 1 root disk      8,   0 Mar 13 01:16 /dev/sda
brw-rw----. 1 root disk      8,   1 Mar 13 01:16 /dev/sda1
brw-rw----. 1 root disk      8,   2 Mar 13 01:16 /dev/sda2
brw-rw----. 1 root disk      8,  16 Mar 13 01:16 /dev/sdb
brw-rw----. 1 root cdrom    11,   0 Mar 13 01:16 /dev/sr0

4. Character device file (c)

Provides a serial stream of input or output.Your terminals are classic example for this type of files.

[root@server1 ~]# ls -l /dev/* |grep ^c
crw-rw-rw-. 1 root tty       5,   0 Mar 13 01:16 /dev/tty
crw--w----. 1 root tty       4,   0 Mar 13 01:16 /dev/tty0
crw--w----. 1 root tty       4,   1 Mar 13 01:18 /dev/tty1
crw--w----. 1 root tty       4,  10 Mar 13 01:16 /dev/tty10

5. Named Pipe file Or Just a pipe file (p)

The other name of pipe is a “named” pipe, which is sometimes called a FIFO. FIFO stands for “First In, First Out” and refers to the property that the order of bytes going in is the same coming out. The “name” of a named pipe is actually a file name within the file system.

Create pipe file using below command
# mkfifo pipe

[root@server1 ~]# ls -l |grep ^p
prw-r--r--. 1 root root    0 Mar 13 04:52 pipe

6. symbolic link file (l)

These are linked files to other files. They are either Directory/Regular File. The inode number for this file and its parent files are same. There are two types of link files available in Linux/Unix ie soft and hard link. 

#ls -l |grep ^l

7. Socket file (s)

A socket file is used to pass information between applications for communication purpose 

#ls -l |grep ^s

How did you feel about this article....?