Month: July 2021

Nullifying a log file in Linux

At this point, you already have the file which is causing the problem and you want to nullify it so just do as;

#cat <logfile.Name> | gzip -v9 > (logfile).(date-time)
# cat lastlog | gzip -v9 > lastlog.300721-0648
#cat /dev/null > lastlog


# cp /var/adm/syslog/syslog.log /var/adm/syslog/syslog.log.bak
# gzip /var/adm/syslog/syslog.log.bak
# cp /dev/null /var/adm/syslog/syslog.log
#cat file1 file2 | gzip > foo.gz

Then you can compress the file;

gzip -v9 <file_name>

Alternate way;

du -sk /var/* | sort -n
du -xam /PARTITION | sort -n | tail -n 40
du -xam / | sort -n | tail -n 40

How to find the biggest files in filesystem – Linux, UNIX, HP-UX

Disk space issues are the most common problems raise in the day-to-day life of Linux system admin. So in this article, you can find out the commands to find out the largest files in your file system which are causing problems for the filesystem.

Find for Large Files under Specific Mountpoint

find /var -xdev -type f -size +500000c -exec ll {} ; | sort -nk 5
find /home -xdev -type f -size +5000000c -exec ll {} ; | sort -nk 5
find /opt -xdev -type f -size +5000000c -exec ll {} ; | sort -nk 5
find /usr -xdev -type f -size +5000000c -exec ll {} ; | sort -nk 5
find /tmp -xdev -type f -size +50000000c -exec ll {} ; | sort -nk 5
find /var -xdev -type f -size +50000000c -exec ll {} ; | sort -nk 5

For Solaris & Linux, replace ‘ll’ with ‘ls -l’

find / -xdev -type f -size +50000000c -exec ls -l {} ; | sort -nk 5
find /usr -xdev -type f -size +50000000c -exec ls -ld {} ; | sort -nk 5
find /var -xdev -type f -size +50000000c -exec ls -ld {} ; | sort -nk 5
find / -xdev -type f -size +50000000c -exec ls -ld {} ; | sort -nk 5
find /nfs/tmp -xdev -type f -size +5000000c -exec ls -ld {} ; | sort -nk 5
find /data -xdev -type f -size +50000000c -exec ls -ld {} ; | sort -nk 5
find /usr1/data1 -xdev -type f -size +50000000c -exec ls -ld {} ; | sort -nk 5
find /apps -xdev -type f -size +50000000c -exec ls -ld {} ; | sort -nk 5
find /nfsdata -xdev -type f -size +50000000c -exec ls -l {} ; | sort -nk 5
find /see_data -xdev -type f -size +50000000c -exec ls -l {} ; | sort -nk 5


bdf /var

Solaris, Linux, and AIX

df -k /var

Where -k report size in KB

df -h /var

-h report size in GB / Human-readable

df -h /var

size in GB (Solaris 9++)

Linux interview questions

Linux Interview Questions From Real Interviewer

Before we start a technical side, I think the first step to winning an interview is to go through with few things that will help you be successful at the interview.

Analyzing The Position:

It would be best if you began with a systematic review of the job description. Your objective is to collect as much information as possible about how the job and what knowledge and competencies are needed to perform your future job.

Take a close look at the official job description. Consider the environment in which the job is going to be performed. Are there any special skills required? what tools and software you need to know to perform this job.

Make a note of any tools that are being used to perform the tasks of the job, For instance, with the kind of servers, storage protocols, and operating systems they are using, and familiarise yourself with all those tools before the interview.

You can also talk with those who have held the job in the past. If you don’t know anyone, just try to find them through and scan their profiles for tools and skillsets they have used.

Check what competencies and skills contributed to their success? Did the lack of specific competencies or skills cause or contribute to difficulties that they experienced on the job?

What you should have and what interviewers are looking for:

Before they offer you the contract for a long-term relationship with you, they want to know what’s in it for them.

  • Problem-solving skills. It would be best if you have a couple of stories in which you solved the problem independently. Bring any certificate if you got any. 
  • Good people skills. The ability to foster good working relationships is a vital business skill. Discuss situations where you worked well with others. For instance, you can narrate your stories of helping co-workers under challenging conditions.
  • Getting Things Done Skills. The ability to get things done. Mention those times when your good judgment or ingenuity helped you close a deal.
So let’s start our main topic for which you are visiting this post.

1. Tell us about your experience with Linux and the projects you have accomplished?

In response to this question, you should tell your experiences, such as your current or previous job experiences and all the big/small projects you have done. Don’t trust your present memory. Please write it down and try to be fluent in these details.

2. What is the difference between Linux & Unix?

Unix: It is considered the mother of most operating systems. It is a Proprietary operating system and original code developed by AT & T. Originally the Bourne shell. Compatible with PA and Itanium machines. It is also compatible with many command interpreters. AIX and BSD are the renowned flavors of UNIX.
    Linux: The code developed by Linus Torvalds. By default, the shell is BASH (Bourne Again Shell) and can use multiple shells. Ubuntu, Debian , centos, and Redhat are the different flavors of Linux.

      3. What is the shell?

      I think the simplest answer is  “shell is a language to communicate with a computer.”Bash or the Bourne-Again Shell is the most widely used shell among Linux admins.  

      4. What is the structure of Linux filesystem?

      Linux interview Questions form Real interviewer

      All files on a Linux system are stored on file systems, which are inverted into a single inverted tree of directories, known as a file-system hierarchy. This tree is invented because the root of the tree is to be at the top of the hierarchy, and the branches of directories and subdirectories stretch below the root. 
      /Is the root directory at the top of the file-system hierarchy.
      /usrIt contains installed software, shared libraries, includes files and read-only program data. Subdirectories include /usr/bin user commands, /usr/sbin/ system admin commands, /usr/local: locally customized software
      /etcconfiguration files specific to this system
      /varvariable data specific to this system that should persist between boots. Files that dynamically change such as databases, cache directories, log files, and website content the most famous one
      /runRuntime data for processes started since the last system boots.
      /homeHome directories are where regular users store their personal data and configuration files
      /tmpThis directory has a world-writable space. Any user can put files here, and within 30 days, the files will be deleted.

      5. Which directory contains regular commands and utilities?

      /usr contains regular commands and utilities.

      6. What is the root account?

      The root account is a system administrator account and has all the powers to give you complete control of the system. Here you can create and maintain user accounts, assigning different permissions for each account. It is the default account every time you install Linux.

      5. How to ensure that newly created users have passwords that must be changed every 90 days?

      you can set password policy from the file /etc/login.defs by changing the value ” PASS_MAX_Days” to 90.

      6. How you will configure the administrative rights for all members of the group named consultants that its members are able to execute any command as any user?

      Create the new file /etc/sudoers.d/consultants and add the following content to it. You can use the sudo vim /etc/sudoers.d/consultants command to perform this step.%consultants ALL=(ALL) ALL

      7. What are symbolic links?

      Symbolic links are files that act as pointers to other files.

      8. If you lost your root password, can you change the root password, and how?

      We can reset the root password, and you can look into this link for the details.

      9. What is initialzation?

      The term “init” is the program on Unix-like system which spawns all other processes. It runs as a daemon and typically has a PID 1.

      10. What is a pstree?

      This is the command to check the running processes.

      11.What will you do if you receive the alert that your partition is full?

      First of all, check which files are the biggest ones on the affected partition. In most cases, log files are there which are causing the troubles, so in this case, you can zip the file after nullifying.

      12. How can you find out that how much memory is being used by your server?

      You can take the help of different tools to find the memory usage on your system.
      free - m

      17. What is a recommendation of the SWAP partition under a Linux system?

      The recommended size for a swap partition is twice the amount of physical memory available on the system. However, if you cant put the double in size, you can put the same amount as memory in your system.

      18. How to display IP address?

      ip address show

      19. How to displaying the Network performance Statistics?

      ip -s link show ens3       #ens3 is your interface

      20. How to displaying the Routing table?

      ip route

      21. How to Tracing Route Taken by Traffic?

      tracepath tracepath options ICMP ( -I) TCP (-T)*traceroute command not installed by default

      22. Troubleshooting Ports and Services?

      ss command is meant to replace netstat
      ss -ta
      -n show numbers insted of names for interfaces and ports
      -t show TCP sockets
      -u Show UDP sockets
      -l show listening sockets
      -a show all ( listening and establisted)

      23. How to show the status of the network devices?

             nmcli dev status

      24. How to show the connection status?

               nmcli con show

      25. How to list on active connection?

           nmcli con show --active

      26. How to control network connections?

      You must be able to demonstrate how to control your network connections.
      nmcli con up static-ens3
      nmcli dev dis ens3
      nmcli con show static-ens3
      nmcli con reload
      nmcli con down "static-ens3"
      nmcli con up "static-ens3"

      27. How to remove a network connection?

      nmcli con del static-ens3

      28. What are nmcli commands?

      nmcli dev status : show the networkManagaer stusus of all netwokr interfaces
      nmcli con show : List all connections
      nmcli con show NAME : list the current settings for the connection name
      nmcli con add con-name name Add a new connection named name
      nmcli con mod name modify the connectiuon anem
      nmcli con up name enable it and make it up
      nmcli dev dis devf disconnects it.
      nmacli con del name Deletes

      29. How to change the System hostname?

      hostnameclt set-hostname
      hostnamectl status

      30. How to test the DNS name resolution?

      host IP

      31. How to configure the name resolution without the DNS server?

      Command to check the hostname in Redhat is getent hosts hostnameIf you don’t have a DNS server you can configure it through /etc/hosts.getent hosts hostname command can be used to test the hostname resolution using the /etc/hosts file.

      32. How to Manage SELinux?

      Selinux is a set of security rules that determine which process can access which files, directory, and ports. every file process directory and port has a special security label called an SELinux context.By default, policy does not allow any interaction.SELinux has several contexts: user, role, type, and sensitivity.

      33. How to find out the current SELinux policy?

      [root@servera ~]# grep '^SELINUX' /etc/selinux/config
      *if you want to disable you, then replace enforcing to disabled and reboot the server.

      34. How to Change SELinux context?

      This is how you can change the /virtual context
      semanage fcontext -a -t httpd_sys_content_t '/virtual(/.*)?'
      restorecon -RFvv /virtual

      35. How to check the current context?

      ls -zD /virtual OR ls -Zd /var/www

      36. How are you troubleshooting SELinux issues?

      You can check the logs from autdit.log
      tail /var/log/audit/audit.log
      And do,
      less /var/log/messages and search like this / sealert and copy past sealert -l b1c9cc8f-a953-4625-b79b-82c4f4f1fee3
      ausearch -m AVC -ts recent
      -ts time based search

      39. How to check if ports are open or not?

      There are many ways to perform this activity, but few famous are shown below:by using /etc/services
      # cat /etc/services | grep " 123/"
      Diagnostic Steps
      by using netstat
      # netstat -tulpn | grep :123
      udp 0 0* 26868/chronyd
      udp6 0 0 :::123 :::* 26868/chronyd
      By using nmap  (nmap is a utility for network discovery and security auditing)
      # nmap -p 123 <server-ip>
      By default nmap would give details of TCP port 123. To get details of 123/udp port use below command :
      # nmap -sU -p 123 <server-ip>

      41. what is systemd?

      systemd uses units to manage different types of objects.

      41. What is service units?

      service units have service extensions and represent system services, for example web servers.

      42. What are socket units?

      socket units have a .socket extension and represent inter-process communication sockets that systemd should monitor.

      43. What is path units?

      Path units have .path extension and are used to delay the activation of service until a specific file system change occurred.

      44. What is systemctl?

      It is used to manage units. you can get more information with systemctl -t help

      45. How to check all the services and their status?

      systemctl list-units --type=service

      46. How to view the status of the service in Linux?

      systemctl status name.type
      systemctl status sshd.service
      systemctl status chronyd

      47. How to verify the status of the service?

      systemctl is-active sshd.service

      47. How to check if service is enabled during boot?

      systemctl is-enabled sshd.service

      48. How to check if the service is failed during boot?

      systemctl is-failed sshd.service

      49. how to display to check all the services failed during boot?

      systemctl is-failed –type=service 

      50. How you define the booting process?

      • The server is powered on. The system firmware runs a POST  (UFFI or BIOS) and stats to initialize the hardware.
      • System firmware searches for a bootable device.
      • System firmware reads a boot loader from the disk and then passes control of the system to the boot loader.
      • In REDHAT boot loader is GRand Unified bootloader version 2 (GRUB2) which loads configuration from this file ( /boot/groub2/grub.cfg).
      • Now, you will have the option to select the kernel and once you select the kernel, the boot loader loads the kernel and Initramfs from the disk.
      • boot loader hands over the kernel to check the location of the intramfs in the memory. Here kernel initiates all the hardware by finding out the drivers.
      • systemd instance from intiramfs executes all units for the

      51. What are the system Targets modes

      systemd targets are represented by targets units, but in earlier versions, prior to RHEL 7, the system was coming with SysV runlevels.

      52. how to check the default target?

      systemctl get-default

      53. how to view the target units?

      systemctl list-units --type target --all

      54. How to change the default target?

      systemctl get-default
      systemctl set-default

      55. How to boot in the rescue mode?

      systemctl rescue

      56. How to check the available subscription?

      subscription-manager list --available | less

      57. How to attach the subscription?

      subscription-manager attach --auto
      The most important yum command
      yum help
      yum list 'http*'
      yum search all 'web server'
      yum info httpd
      yum provides /var/www/html
      yum list kernel
      yum remove httpd
      yum group list
      yum group "RPM Development Tools"

      58. All the rpm-related history save in which file?

      /var/log/dnf.rpm.log or yum history

      59. At what location system save your repo files?


      60. How to check which repos are attached to the system? 

      yum repolist all

      What is Web Host Manager (WHM) & what can you do with it

      If you are a website owner or reseller you may have heard of WHM but may not be familiar with its features and how to use it effectively. This post provides in-depth explanation of WHM primary functions and features.

      What is WHM?

      The WebHost Manager (WHM) interface has been specially built for hosting providers and resellers to get the most out of their Linux based machines so they can offer the best service to their customers. The WHM interface is shown below.


      WHM Features

      Management of cPanel hosting packages and accounts

      WHM is used to easily create custom hosting packages and accounts for cPanel users. The packages feature allows you to choose the services you want to provide for each cPanel user account. You can create pricing tiers and suspend or terminate user accounts. WHM allows you to offer special reseller hosting so you can scale your hosting business.


      Easily transfer cPanel accounts from remote servers with no hassle. You will need to enter only the remote server IP address and ssh login details. It is advised not to select experimental features during remote transfer of cPanel accounts.


      WHM has advanced server monitoring tools. View how your account resources are being consumed and get actionable insights on critical issues effecting your network.

      Server security

      WHM has many security tools with tight integration with cPanel accounts. You can easily whitelist or blacklist IP, regions, or countries. Deployment of SSL certificates on all domains is automated with cPanel and Let’s encrypt SSL certificates. With Exim, you can encrypt all outgoing email messages. A new feature of WHM security is multi-factor authentication which harden cPanel account security.

      How to reset PTR/rDNS records in cPanel WHM

      If issue arises in email delivery about wrong PTR/rDNS record than click the following option in Exim configuration manager.

      Rebuild Reverse DNS Cache and Update Mail HELO

      This setting updates the reverse DNS cache and user domains for mail HELO. This setting only appears when you enable the Use the reverse DNS entry for the mail HELO/EHLO if available setting.

      Above solution is is the best way when you do not set PTR records prior to installing cPanel. cPanel will detect wrong PTR records due to which Exim mail server will not function. Setting proper PTR records is mandatory. Make sure CNAME is also set in domain DNS settings which is by default used by outlook and other mail clients.