How to Copy or Move Files Based on Date Modified on Linux

Q. How to copy or Move the files and folder based on date modified on linux ?

A. Follow this steps :

1. Check the files modified date :

# ls -lrt

Output :

drwxr-xr-x  2       507 root           4096 Mar  3 21:00 ioncube
-rw-r--r--  1 root      root        5641209 Mar  3 21:04 ioncube_loaders_lin_x86-64.tar.gz
-rw-r--r--  1 root      root         635678 Mar  8 11:28 facilemanager-complete-1.3.1.tar.gz
-rw-r--r--  1 root      root              0 May 12 00:08 file1
-rw-r--r--  1 root      root              0 May 12 00:08 file2
-rw-r--r--  1 root      root              0 May 12 00:08 file3
-rw-r--r--  1 root      root              0 May 12 00:08 file4
-rw-r--r--  1 root      root              0 May 12 00:08 file5

2. Create May directory under tmp, where the destination of the listed files :

# mkdir -p /tmp/May

3. Run the following command to display the files for date “May 12” and Move it to /tmp/May folder :

# for i in `ls -lrt | grep "May 12" | awk '{print $9}' `; do mv $i* /tmp/May; done


4. Run the following command to display the files for date “May 12” and copy it to /tmp/May folder :

# for i in `ls -lrt | grep "May 12" | awk '{print $9}' `; do cp -p $i* /tmp/May; done

How to Check and Verify the Version of Python on CentOS 6 / CentOS 7

Python is a popular programming language, which is widely used, high-level programming languages ??and has a design philosophy that emphasizes code readability. It is considered as a programming language that is easy to learn and master because of its focus on readability. Python syntax allows programmers to express concepts in fewer lines of code as possible in languages ??other programming such as C ++ or Java. This article show you how to check and verify the version of Python on CentOS 6, CentOS 7, RHEL 6 and RHEL 7.

1. Check Python version :

[root@vps ~]# python --version
Python 2.7.5

2. Enter python command line :

[root@vps ~]# python
Python 2.7.5 (default, Jun 17 2014, 18:11:42)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

3. To exit, run the following command :

>>> quit()

How to Disable Autostart for a Service at boot on Linux CentOS 7 / RHEL 7

Question : Due to some reason, I had to stop a service on linux CentOS 7. But when i restarted the server, the service starts again automatically. How to stop or disabled auto start services at boot ?

Answer : Just issue the following command to disabled auto start for particular service.

Syntax :

sudo systemctl disable <service-named>.service

Example :

[root@centos7 ~]# sudo systemctl disable named-chroot.service
rm '/etc/systemd/system/'

How to Create an Archive using tar Command

In Linux, tar command is the primary utility to create compressed archive files and directories. “tar” stands for tape archive and it is actually archiving file format. The following example will show you how to creating an archive using tar command.

tar option(s) archive_name file_name(s)
A, –catenate, –concatenateAppend tar files to an archive.
c, –createCreate a new archive.
d, –diff, –compareCalculate any differences between the archive and the file system.
–deleteDelete from the archive. (This function doesn’t work on magnetic tapes).
r, –appendAppend files to the end of a tar archive.
t, –listList the contents of an archive.
–test-labelTest the archive label, and exit.
u, –updateAppend files, but only those that are newer than the copy in the archive.
x, –extract, –getExtract files from an archive.
-v, –verboseOperate verbosely.
-z, –gzip, –gunzipThis option tells tar to read or write archives through gzip, allowing tar to directly operate on several kinds of compressed archives transparently. This option should be used, for example, when operating on files with the extension.tar.gz.
-Z, –compress, –uncompresstar will use the compress program when operating on files.

How to archive /home/scriptsmy directory :

[root@vps ~]# tar -cvf scriptsmy-07-11-2014.tar /home/scriptsmy

How to archive /home/scriptsmy directory then gunzip it :

[root@vps ~]# tar cvzf scriptsmy-07-11-2014.tar.gz /home/scriptsmy

How to Fix the ‘Shell Shock’ bash Vulnerability in Linux

Q. Linux system administrators who maintaining the servers that are exposed to the Internet should be the most concerned about this Shell Shock’ bash Vulnerability or attack. Most of the patches are now available from the vendors that should close this security hole. For those who still haven’t check your linux system, below are the recommended unofficial procedure in order to ensure you server are not vulnerable from Shellshock attack.

A. Follow the following procedure to secure you system.

1. As a root, login to your linux system and run the following command :

[root@centos7 ~]# env x='() { :ignored function;}; echo vulnerable' bash

2. Skip the next step if you command did not say vulnerable, meaning your bash is up to date.

If you see the return message below, kindly proceed to next steps.
Example :

[root@centos7 ~]# env x='() { :ignored function;}; echo vulnerable' bash

3. Perform update for bash :

[root@centos7 ~]# yum update bash -y

4. Check your current bash version. If in CentOS 7 or RHEL 7 the fix is in bash-4.2.45 :

[root@centos7 ~]# rpm -qa | grep bash

Please take a look of below details from redhat article.

How does this impact systems

This issue affects all products which use the Bash shell and parse values of environment variables. This issue is especially dangerous as there are many possible ways Bash can be called by an application. Quite often if an application executes another binary, Bash is invoked to accomplish this. Because of the pervasive use of the Bash shell, this issue is quite serious and should be treated as such.

All versions prior to those listed as updates for this issue are vulnerable to some degree.

Products Affected:

Product/ChannelFixed in packageRemediation details
Red Hat Enterprise Linux 7bash-4.2.45-5.el7_0.4Red Hat Enterprise Linux
Red Hat Enterprise Linux 6bash-4.1.2-15.el6_5.2Red Hat Enterprise Linux
bash-4.1.2-15.el6_5.1.sjis.2Red Hat Enterprise Linux
bash-4.1.2-9.el6_2.2Red Hat Enterprise Linux 6.2 AUS
bash-4.1.2-15.el6_4.2Red Hat Enterprise Linux 6.4 EUS
Red Hat Enterprise Linux 5bash-3.2-33.el5_11.4Red Hat Enterprise Linux
bash-3.2-33.el5_11.1.sjis.2Red Hat Enterprise Linux
bash-3.2-24.el5_6.2Red Hat Enterprise Linux 5.6 LL
bash-3.2-32.el5_9.3Red Hat Enterprise Linux 5.9 EUS
Red Hat Enterprise Linux 4bash-3.0-27.el4.4Red Hat Enterprise Linux 4

Common Configuration Examples:

Red Hat performed an analysis to better understand the magnitude of this issue and how it affects various configurations. The below list is not exhaustive, but is meant to give some examples of how this issue affects certain configurations, and why the high level of complexity makes it impossible to specify something is not affected by this issue. The best course of action is to upgrade Bash to a fixed version.

httpdCGI scripts are likely affected by this issue: when a CGI script is run by the web server, it uses environment variables to pass data to the script. These environment variables can be controlled by the attacker. If the CGI script calls Bash, the script could execute arbitrary code as the httpd user. mod_php, mod_perl, and mod_python do not use environment variables and we believe they are not affected.
Secure Shell (SSH)It is not uncommon to restrict remote commands that a user can run via SSH, such as rsync or git. In these instances, this issue can be used to execute any command, not just the restricted command.
dhclientThe Dynamic Host Configuration Protocol Client (dhclient) is used to automatically obtain network configuration information via DHCP. This client uses various environment variables and runs Bash to configure the network interface. Connecting to a malicious DHCP server could allow an attacker to run arbitrary code on the client machine.
CUPSIt is believed that CUPS is affected by this issue. Various user supplied values are stored in environment variables when cups filters are executed.
sudoCommands run via sudo are not affected by this issue. Sudo specifically looks for environment variables that are also functions. It could still be possible for the running command to set an environment variable that could cause a Bash child process to execute arbitrary code.
FirefoxWe do not believe Firefox can be forced to set an environment variable in a manner that would allow Bash to run arbitrary commands. It is still advisable to upgrade Bash as it is common to install various plug-ins and extensions that could allow this behavior.
PostfixThe Postfix server will replace various characters with a ?. While the Postfix server does call Bash in a variety of ways, we do not believe an arbitrary environment variable can be set by the server. It is however possible that a filter could set environment variables.

A more detailed analysis of the flaw is available at:

How to Determine Linux Kernel is 32 bit or 64 bit

Question :
I’m running a linux CentOS operating system, but i am not sure the linux kernel is 32 bit or 64 bit. How to determine that ?

Answer :
Kindly issue the following command to check the kernel bit version :

[root@vps ~]# uname -m


[root@vps ~]# uname -r

x86_64 is 64 bit.

Full uname command options :

[root@vps ~]# uname --help
Usage: uname [OPTION]...
Print certain system information.  With no OPTION, same as -s.

  -a, --all                print all information, in the following order,
                             except omit -p and -i if unknown:
  -s, --kernel-name        print the kernel name
  -n, --nodename           print the network node hostname
  -r, --kernel-release     print the kernel release
  -v, --kernel-version     print the kernel version
  -m, --machine            print the machine hardware name
  -p, --processor          print the processor type or "unknown"
  -i, --hardware-platform  print the hardware platform or "unknown"
  -o, --operating-system   print the operating system
      --help     display this help and exit
      --version  output version information and exit

Report uname bugs to
GNU coreutils home page: 
General help using GNU software: 
For complete documentation, run: info coreutils 'uname invocation'

How to Install man Pages Command on CentOS 5.7

Man pages are a common way to learn the commands that are on your system. The man command will give you all the details of a given command, including switches used, and syntax. man formats and displays the on-line manual pages. This post will show the quick steps to install man command on linux CentOS 5.7 server.

[root@CentOS57 ~]# yum install man -y
[root@CentOS57 ~]# yum install man -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base:
 * extras:
 * rpmforge:
 * updates:
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package man.i386 0:1.6d-2.el5 set to be updated
--> Processing Dependency: groff >= 1.18 for package: man
--> Processing Dependency: bzip2 for package: man
--> Processing Dependency: nroff-i18n for package: man
--> Running transaction check
---> Package bzip2.i386 0:1.0.3-6.el5_5 set to be updated
---> Package groff.i386 0: set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

 Package              Arch                Version                         Repository           Size
 man                  i386                1.6d-2.el5                      base                262 k
Installing for dependencies:
 bzip2                i386                1.0.3-6.el5_5                   base                 49 k
 groff                i386                       base                1.9 M

Transaction Summary
Install       3 Package(s)
Upgrade       0 Package(s)

Total download size: 2.2 M
Downloading Packages:
(1/3): bzip2-1.0.3-6.el5_5.i386.rpm                                          |  49 kB     00:00
(2/3): man-1.6d-2.el5.i386.rpm                                               | 262 kB     00:02
(3/3): groff-                                        | 1.9 MB     00:17
Total                                                               104 kB/s | 2.2 MB     00:21
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : bzip2                                                                        1/3
  Installing     : groff                                                                        2/3
  Installing     : man                                                                          3/3

  man.i386 0:1.6d-2.el5

Dependency Installed:
  bzip2.i386 0:1.0.3-6.el5_5                      groff.i386 0:


To man command manual simply run “man man” as below :

[root@CentOS57 ~]# man man
man(1)                                                                  man(1)

       man - format and display the on-line manual pages

       man  [-acdfFhkKtwW]  [--path]  [-m system] [-p string] [-C config_file]
       [-M pathlist] [-P pager] [-B browser] [-H htmlpager] [-S  section_list]
       [section] name ...

       man formats and displays the on-line manual pages.  If you specify sec-
       tion, man only looks in that section of the manual.  name  is  normally
       the  name of the manual page, which is typically the name of a command,
       function, or file.  However, if name contains  a  slash  (/)  then  man
       interprets  it  as a file specification, so that you can do man ./foo.5
       or even man /cd/foo/bar.1.gz.

       See below for a description of where man  looks  for  the  manual  page

       -C  config_file
              Specify   the   configuration   file  to  use;  the  default  is
              /etc/man.config.  (See man.config(5).)

       -M  path
              Specify the list of directories to search for man pages.   Sepa-
              rate  the directories with colons.  An empty list is the same as
              not specifying -M at all.  See SEARCH PATH FOR MANUAL PAGES.

       -P  pager
              Specify which pager to use.  This option overrides the  MANPAGER
              environment  variable,  which  in turn overrides the PAGER vari-
              able.  By default, man uses /usr/bin/less -is.

       -B     Specify which browser to use on HTML files.  This  option  over-
              rides  the  BROWSER  environment  variable. By default, man uses

       -H     Specify a command that renders HTML files as text.  This  option
              overrides  the  HTMLPAGER  environment variable. By default, man
              uses /bin/cat,

       -S  section_list
              List is a colon separated list of  manual  sections  to  search.
              This option overrides the MANSECT environment variable.

       -a     By default, man will exit after displaying the first manual page
              it finds.  Using this option forces man to display all the  man-
              ual pages that match name, not just the first.

       -c     Reformat  the  source man page, even when an up-to-date cat page
              exists.  This can be meaningful if the cat  page  was  formatted
              for  a screen with a different number of columns, or if the pre-
              formatted page is corrupted.

       -d     Donât actually display the man  pages,  but  do  print  gobs  of
              debugging information.

       -D     Both display and print debugging info.

       -f     Equivalent to whatis.

       -F or --preformat
              Format only - do not display.

       -h     Print a help message and exit.

       -k     Equivalent to apropos.

       -K     Search  for  the  specified  string in *all* man pages. Warning:
              this is probably very slow!  It  helps  to  specify  a  section.
              (Just  to  give  a  rough idea, on my machine this takes about a
              minute per 500 man pages.)

       -m  system
              Specify an alternate set of man pages to  search  based  on  the
              system name given.

       -p  string
              Specify  the  sequence  of  preprocessors to run before nroff or
              troff.  Not all installations will have a full set of preproces-
              sors.   Some of the preprocessors and the letters used to desig-
              nate them are: eqn (e), grap (g), pic (p), tbl (t), vgrind  (v),
              refer  (r).   This  option  overrides the MANROFFSEQ environment

       -t     Use /usr/bin/groff -Tps -mandoc to format the manual page, pass-
              ing  the  output  to  stdout.   The  default  output  format  of
              /usr/bin/groff -Tps -mandoc is Postscript, refer to  the  manual
              page  of  /usr/bin/groff -Tps -mandoc for ways to pick an alter-
              nate format.

       Depending on the selected  format  and  the  availability  of  printing
       devices,  the  output  may  need  to  be  passed through some filter or
       another before being printed.

       -w or --path
              Donât actually display the man pages, but  do  print  the  loca-
              tion(s) of the files that would be formatted or displayed. If no
              argument is given: display (on stdout) the list  of  directories
              that  is  searched by man for man pages. If manpath is a link to
              man, then "manpath" is equivalent to "man --path".

       -W     Like -w, but print file names one per line,  without  additional
              information.   This is useful in shell commands like man -aW man
              | xargs ls -l

How to Install vim on RHEL 6

In this post, i will show on how to install vim on Redhat Enterprise Linux 6 (RHEL 6) Linux server. Vim stands for ‘Vi Improved’. Vi is one of the most popular and powerful editors in the Unix systems. Vim is an advanced text editor, alternative editor for VI and it’s highly configurable text editor built to enable efficient text editing. It is an improved version of the vi editor distributed with most UNIX systems. If your RHEL 6 server doesn’t have vim installed, you will get the following error :

    [root@rhel6 ~]# vim /etc/httpd/conf/httpd.conf
    -bash: /usr/bin/vim: No such file or directory

Assumed that you have set up local yum repository using your DVDrom. If you haven’t set up the local yum repository, please proceed to this steps :
How to Setup Local Yum Repository from CD-ROM/DVD-ROM image on RHEL 6

Simply run this command to install vim on RHEL 6 :

    [root@rhel6 ~]# yum install vim-enhanced -y
    Loaded plugins: rhnplugin
    This system is not registered with RHN.
    RHN support will be disabled.
    Setting up Install Process
    Resolving Dependencies
    --> Running transaction check
    ---> Package vim-enhanced.i686 2:7.2.411-1.4.el6 set to be updated
    --> Finished Dependency Resolution
    Dependencies Resolved
     Package               Arch          Version                    Repository                     Size
     vim-enhanced          i686          2:7.2.411-1.4.el6          DVD-RHEL6-Repository          839 k
    Transaction Summary
    Install       1 Package(s)
    Upgrade       0 Package(s)
    Total download size: 839 k
    Installed size: 1.8 M
    Downloading Packages:
    Running rpm_check_debug
    Running Transaction Test
    Transaction Test Succeeded
    Running Transaction
      Installing     : 2:vim-enhanced-7.2.411-1.4.el6.i686                                          1/1
      vim-enhanced.i686 2:7.2.411-1.4.el6

You can check the details of this vim-enhanced package using this command :

    [root@rhel6 ~]# yum info vim-enhanced
    Loaded plugins: rhnplugin
    This system is not registered with RHN.
    RHN support will be disabled.
    Installed Packages
    Name       : vim-enhanced
    Arch       : i686
    Epoch      : 2
    Version    : 7.2.411
    Release    : 1.4.el6
    Size       : 1.8 M
    Repo       : installed
    From repo  : DVD-RHEL6-Repository
    Summary    : A version of the VIM editor which includes recent enhancements
    URL        :
    License    : Vim and GPLv2+ and BSD and LGPLv2+ and Open Publication
    Description: VIM (VIsual editor iMproved) is an updated and improved version of the
               : vi editor.  Vi was the first real screen-based editor for UNIX, and is
               : still very popular.  VIM improves on vi by adding new features:
               : multiple windows, multi-level undo, block highlighting and more.  The
               : vim-enhanced package contains a version of VIM with extra, recently
               : introduced features like Python and Perl interpreters.
               : Install the vim-enhanced package if you'd like to use a version of the
               : VIM editor which includes recently added enhancements like
               : interpreters for the Python and Perl scripting languages.  You'll also
               : need to install the vim-common package.

Note that you must be the root/administrator to install the package.

How to Check Hard Disk Size and Hard Disk Usage on CentOS 6.2

In this post, i will share the simple command to check the Hard Disk size and usage on CentOS 6.2. This command is a basic command for linux operating system.

To view and list of the usage of each partition in the server :

    [root@centos62 ~]# df -h
    Filesystem            Size  Used Avail Use% Mounted on
                           13G  1.8G   10G  15% /
    tmpfs                 504M     0  504M   0% /dev/shm
    /dev/sda1             485M   48M  412M  11% /boot

df command will displays the total, used, and available free space on all currently mounted filesystems.

To list the size of a specific directory, run the following command :

    [root@centos62 ~]# du -sh /root
    2.6M    /root

du command reports disk usage. It will shows the disk space used by the files and directories in a directory. The -h option makes the output easier to read by user.