Tricky RHCE questions

  • How to find out which init level you are in?
  • [root@rhel5 ~]# ps -ef | more
    UID PID PPID C STIME TTY TIME CMD
    root 1 0 0 22:42 ? 00:00:00 init [5]

    Scheduler is process 0; init is process 1;

  • How to get inode information?
  • [root@rhel5 ~]# ls -i anaconda-ks.cfg 
    370783 anaconda-ks.cfg
    [root@rhel5 ~]#
  • How to debug shell script?
  • To turn debug on:

    set -x

    To turn debug off:

    set +x
  • Another way is to create function inside shell script:
  • #!/bin/bash
    _DEBUG="on"
    function DEBUG()
    {
    [ "$_DEBUG" == "on" ] && $@ || :
    }
    DEBUG echo 'Reading files'
    for i in *
    do
    grep 'something' $i > /dev/null
    [ $? -eq 0 ] && echo "Found in $i file" || :
    done
    DEBUG set -x
    a=2
    b=3
    c=$(( $a + $b ))
    DEBUG set +x
    echo "$a + $b = $c"
  • How to get list of local users
  • [root@rhel5 ~]# cat /etc/passwd |grep "/home" |cut -d: -f1
    vernon
    olivia
    garry
  • How to delete files in /tmp directory, that match pattern "workspace.*" and are 7 days old?
  • find /tmp -name workspace.* -mtime +7 -maxdepth 1 | more
    find /tmp -name workspace.* -mtime +7 -maxdepth 1 -exec rm -f {} \;
  • How to Process Shell Output with Perl?
  • zcat oui.txt | perl -ne 'if ($_ =~ m/(\w{2})-(\w{2})-(\w{2})\s+\(hex\)\s+(.*)/) { print lc($1).lc($2).".".lc($3).",$4\n"; }'
    

Moving your apps to Amazon or Miscrosoft Clouds?

We can help you analyze your existing infrastructure, identify the cost savings we can achieve by migrating to a cloud provider. We can then execute end-to-end migration plan of your infrastructure and bringing down your TCO.

Cloud Computing

Ready for IPv6 Migration?

The Internet is running out of the equivalent of phone numbers - familiar problem, non-trivial solution.

The world has to move to IPv6, with its 128-bit addresses. But that's easier said than done.

IPv6 Migration

Are you fluent in "Linux"?

Learn Linux from a leading expert and quickly master you Linux skills.

Learn how to simplify your workflow and increase your productivity using tips and techniques of the pros.

Ideal training for Corporate IT Beginners and Advanced IT Admins alike.

Corporate Linux Training

Who's Online

We have 8 guests and no members online