How to shutdown/poweroff a Linux / Unix machine via command line

To shutdown the Linux machine you can use  the  shutdown, halt, Poweroff  and reboot command as a root. There are many way to shudown a Linux / Unix machine via command line shown bellow.

To poweroff a linux machine with ‘ reboot ‘ command ,you can use ‘ reboot ‘ command ‘ -P’ or ‘ –poweroff’ option .

[root@localhost ~]# reboot -P

To poweroff a linux machine with ‘ halt ‘command ,you can use ‘ halt ‘ command ‘ -P’ or ‘ –poweroff’ option .

[root@localhost ~]# halt -P

To shutdowna linux machine  immediatly

[root@localhost ~]# shutdown -h now

OR

[root@localhost ~]# poweroff

OR

[root@localhost ~]# shutdown
Shutdown scheduled for Thu 2018-01-04 13:17:12 IST, use ‘shutdown -c’ to cancel.
[root@localhost ~]#
Broadcast message from root@localhost.localadmin (Thu 2018-01-04 13:16:12 IST):

The system is going down for power-off at Thu 2018-01-04 13:17:12 IST![root@localhost ~]#

If you want to shutdown a Linux / Unix machine with a specific time , you can use ‘shutdown ‘ command with ‘ -P ‘ or ‘ –poweroff ‘ option.

Syntax:  shutdown [OPTIONS] [TIME in 24 Howr format] [Wall Message]

[root@localhost ~]# shutdown -P +10 ” The system is shutdown after 10 minute due to hardware replace “
Shutdown scheduled for Thu 2018-01-04 12:27:43 IST, use ‘shutdown -c’ to cancel.
[root@localhost ~]#
Broadcast message from root@localhost.localadmin (Thu 2018-01-04 12:17:43 IST):

The system is shutdown after 10 minute due to hardware replace
The system is going down for power-off at Thu 2018-01-04 12:27:43 IST!

[root@localhost ~]# 

OR

[root@localhost ~]# shutdown -h +10 ” The system is shutdown after 10 minute due to hardware replace “
Shutdown scheduled for Thu 2018-01-04 12:42:23 IST, use ‘shutdown -c’ to cancel.
[root@localhost ~]#
Broadcast message from root@localhost.localadmin (Thu 2018-01-04 12:32:23 IST):

The system is shutdown after 10 minute due to hardware replace
The system is going down for power-off at Thu 2018-01-04 12:42:23 IST!

[root@localhost ~]# 

How to fix an error “At least xMB more space needed on the /boot filesystem. “

Transaction check error:
installing package kernel-3.10.0-693.11.1.el7.x86_64 needs 232KB on the /boot filesystem

Error Summary
————-
Disk Requirements:
At least 1MB more space needed on the /boot filesystem

When this error has been coming we first check the free space in /boot partition

[root@localhost ~]# df -kh
Filesystem            Size           Used            Avail              Use%                 Mounted on
/dev/sda3               18G           7.2G             11G                  41%                            /
devtmpfs               348M         0                   348M               0%                             /dev   
tmpfs                      363M         0                  363M                0%                             /dev/shm
tmpfs                      363M        15M              348M                5%                             /run
tmpfs                      363M         0                   363M                0%                             /sys/fs/cgroup
/dev/sda1               297M         267M            31M                 90%                            /boot
tmpfs                      73M           12K              73M                   1%                             /run/user/42
tmpfs                       73M          0                    73M                  0%                             /run/user/0

/boot partition is 90 % full. Now you check installed kernel 

[root@localhost ~]# rpm -qa | grep kernel

kernel-devel-3.10.0-514.6.1.el7.x86_64
kernel-3.10.0-693.5.2.el7.x86_64
kernel-devel-3.10.0-514.16.1.el7.x86_64
kernel-tools-3.10.0-693.5.2.el7.x86_64
kernel-headers-3.10.0-693.5.2.el7.x86_64
kernel-devel-3.10.0-514.2.2.el7.x86_64
kernel-3.10.0-514.10.2.el7.x86_64
kernel-tools-libs-3.10.0-693.5.2.el7.x86_64
kernel-3.10.0-514.2.2.el7.x86_64
kernel-3.10.0-514.16.1.el7.x86_64
abrt-addon-kerneloops-2.1.11-48.el7.centos.x86_64
kernel-devel-3.10.0-693.5.2.el7.x86_64
kernel-devel-3.10.0-514.10.2.el7.x86_64
[root@localhost ~]#

Display current kernel running on the machine use the following command

[root@localhost ~]# uname -r
3.10.0-693.5.2.el7.x86_64

So remove the 2 oldest kernel

[root@localhost ~]# rpm -e kernel-3.10.0-514.2.2.el7.x86_64

[root@localhost ~]# rpm -e kernel-3.10.0-514.16.1.el7.x86_64

Check the free space in /boot partition

[root@localhost ~]# df -kh
Filesystem            Size           Used            Avail              Use%                 Mounted on
/dev/sda3               18G           7.2G             11G                  41%                            /
devtmpfs               348M         0                   348M               0%                             /dev   
tmpfs                      363M         0                  363M                0%                             /dev/shm
tmpfs                      363M        15M              348M                5%                             /run
tmpfs                      363M         0                   363M                0%                             /sys/fs/cgroup
/dev/sda1               297M         164M            133M                56%                            /boot
tmpfs                      73M           12K              73M                   1%                             /run/user/42
tmpfs                       73M          0                    73M                  0%                             /run/user/0

As you can see freed space more  from required amount of space. So now you can update kernel freely with “yum -y update kernel “command.

How to Synchronizing the system clock with a remote server in CentOS /Ubuntu Linux

To enable automatic synchronization of the system clock with a remote server , you can use ‘ timedatectl’ command as a root.

To check NTP status :

[root@localhost ~]# timedatectl

Local time: Sat 2017-12-09 22:01:35 IST

Universal time: Sat 2017-12-09 16:31:35 UTC

RTC time: Sat 2017-12-09 16:31:35

Time zone: Asia/Kolkata (IST, +0530)

NTP enabled: no
NTP synchronized: yes

RTC in local TZ: no

DST active: n/a

[root@localhost ~]#

Synchronizing the system clock with a remote server :

[root@localhost ~]# timedatectl set-ntp yes

[root@localhost ~]# timedatectl
Local time: Sat 2017-12-09 22:11:20 IST

Universal time: Sat 2017-12-09 16:41:20 UTC

RTC time: Sat 2017-12-09 16:41:20

Time zone: Asia/Kolkata (IST, +0530)

NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
[root@localhost ~]#

 

 

How to lock /unlock user Account in FreeBSD

‘pw ‘ command is responsible to  create, remove, modify & display system users and groups ,it is also used to lock and unlock user account  in FreeBSD. To lock/unlock an account you are loged in as a root.How to lock a user account:

If you want to lock the  user account named ‘Intzar’,you can use ‘pw’ command with ‘lock’ option.

Syntax :   pw lock (user name)

root@:~ # pw lock Intzar

root@:~ #

If user account has been locked .you can’t access it.

root@:~ # su Intzar

su: Sorry

root@:~ #

How to unlock a user account:

If you want to unlock the  user account named ‘Intzar’,you can use ‘pw’ command with ‘unlock’ option.

Syntax :   pw unlock (user name)

root@:~ # pw unlock Intzar
root@:~ #

After unlock the user account you access it

root@:~ # su Intzar

$

‘ Cal ‘ command display calendar, date, month and year in Linux/Unix Operating System

‘cal’ command generally  used to  display a calendar in Linux/Unix OS. .If no options are given with ‘cal’ command it displays the current month calendar.

If you want to display current month calendar , you can use ‘ cal ‘ or  ‘ cal -1 ‘ or ‘ cal –one ‘.

[root@localhost ~]# cal
November 2017

Su Mo Tu We Th Fr Sa
                     1     2     3    4
   6     7     8     9   10  11
12 13  14   15   16   17 18
19   20  21  22   23   24 25
26   27  28  29   30

[root@localhost ~]# cal   -1

November 2017

Su Mo Tu We Th Fr Sa

                     1     2     3    4

   6     7     8     9   10  11

12 13  14   15   16   17 18

19   20  21  22   23   24 25

26   27  28  29   30

[root@localhost ~]# cal   –one

November 2017

Su Mo Tu We Th Fr Sa

                     1     2     3    4

5    6     7     8     9   10  11

12 13  14   15   16   17 18

19   20  21  22   23   24 25

26   27  28  29   30

If you want to display  previous, current and next month calendar, you can use ‘cal ‘ command with -3 or –three option .

[root@localhost ~]# cal -3

sdr

[root@localhost ~]# cal –three

sdr


 

 

 

If you want to display Sunday as first day of week, you can use ‘cal ‘ command with -s or –sunday option .

[root@localhost ~]# cal -s

November 201

Su Mo Tu We Th Fr Sa
                    1     2     3    4
   6     7     8     9   10  11
12 13  14   15   16   17 18
19   20  21  22   23   24 25
26   27  28  29   30

If you want to display Monday as first day of week, you can use ‘cal ‘ command with -m or –monday option .

[root@localhost ~]# cal -m

November 2017

Mo Tu We Th Fr Sa Su
                  2   3    4   5
     7    8     9  10 11 12
13  14  15  16   17 18 19
20   21  22  23  24 25 26
27   28  29  30

If you want to display Julian dates ,you can use ‘cal ‘ command with -j or  –Julian option .

[root@localhost ~]# cal -j

November 2017

Sun Mon Tue Wed Thu Fri Sat
                            305 306 307 308
309  310  311   312  313  314 315
316  317  318  319   320  321 322
323 324   325  326  327  328  329
330 331   332  333  334 

If you want to display whole current year calendar, you can use ‘cal ‘ command with -y or  –year option .

[root@localhost ~]# cal -y

whole cal

If you want to check Version information of the  ‘ cal ‘ utility , you can use -V or –version   option with ‘cal’      

[root@localhost ~]# cal -V
cal from util-linux 2.23.2

All command line options  used with the ‘ cal ‘ command are shown below

___________________________________________________________

Options:                                             Description

____________________________________________________________
-1, –one                 show only current month (default)
-3, –three              show previous, current and next month
-s, –sunday           Sunday as first day of week
-m, –monday       Monday as first day of week
j, –julian              output Julian dates
-y, –year               show whole current year
-V, –version         display version information and exit

How You Upgrade CentOS 6.4 to CentOS 6.7

Firstly You check your Current CentOS Version:

CentOS  has Version detail in centos-release file which is exist in /etc directory 

[root@localhost ~]# cat /etc/centos-release 

CentOS release 6.4 (Final)
[root@localhost ~]#

Before you updating CentOS server you taken your data Backup to another machine or safe remote location .

    Backup all databases ( MySQL, PostgreSQL, etc. )
Backup all configuration files ( Apache, PHP, MySQL, DNS and Other services )
Backup all websites data running in webserver
Backup other services running on the system

Now you update your CentOS Server with the help of Yum Command

[root@localhost ~]# yum -y update

After Successful completion of Yum command you reboot your CentOS server with reboot command such as

[root@localhost ~]# reboot

Broadcast message from root@localhost.localdomain

        (/dev/pts/0) at 2:57 …

The system is going down for reboot NOW!


[root@localhost ~]#

Now your CentOS Server has been successfully   updated

[root@localhost ~]# cat /etc/centos-release


CentOS release 6.7 (Final)


[root@localhost ~]#


How To configure C and C++ Development Environment in Linux ( CentOS / Fedora / Red Hat )

1- Install GNU C/C++ compiler and Essential tools to configure Development Environment:-

If  you have Internet connection and you using CentOS / Fedora / Red Hat then you use Yum Command to install GNU C/C++ compiler and Essential tools.

[root@localhost ~]# yum groupinstall ‘Development Tools’     

2-Check or Verify Installation 

These are the following command to display the version  and location of the compiler.

 [root@localhost ~]# rpm -qa gcc
gcc-4.4.7-11.el6.i686
[root@localhost ~]#

Or

 

[root@localhost ~]# whereis gcc
gcc: /usr/bin/gcc /usr/lib/gcc /usr/libexec/gcc /usr/share/man/man1/gcc.1.gz
[root@localhost ~]# which gcc
/usr/bin/gcc
[root@localhost ~]# gcc –version
gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11)
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@localhost ~]#

3- Compile and Run C/C++ test program on Linux Environment           

i- Create a file called test.c using a text Editor Such as vi, Emacs or Joe etc.

#include<stdio.h>
int main()
{
printf(“This is a Test program for GNU C Compiler\n”);
return 0;
}

Syntax for Compile

 gcc program-source-code.c -o executable-file -name

Syntax for  Run

./executable-file-name

Output of above test program

 

[root@localhost ~]# gcc test.c -o test1
[root@localhost ~]# ./test1
This is a Test program for GNU C Compiler

[root@localhost ~


ii-Create a file called test.cpp using a text Editor Such as vi, Emacs or Joe etc.

#include “iostream”
int main(void)
{
std::cout << “This is a Test C++ program.\n”;
return 0;
}

Syntax for Compile

 g++ program-source-code.cpp -o executable-file -name

Syntax for  Run

./executable-file-name

Output of above test program

[root@localhost ~]# g++ test2.cpp -o test3
[root@localhost ~]# ./test3

This is a Test C++ program.
[root@localhost ~]#