CentOS / RHEL: Check If A Service Is Running Or Not

On CentOS/RHEL, you can use the systemctl command to check if a service is running or not. Example:   systemctl is-active <service-name>.service Replace <service-name> with the actual name of the service you want to check. The .service extension is necessary to specify that it is a system service. The systemctl is-active command returns “active” if … Read more

Linux: Find Out Directory Size Command

You can use the du command in a terminal to find the size of a directory in Linux. Example:   du -sh /path/to/directory The -s flag summarizes the directory size, and -h displays the output in a “human-readable” format (i.e., in GB or MB, instead of blocks). Replace /path/to/directory with the actual path to the … Read more

Awk Floating Point Number Addition Results Are Unexpected

When working with floating-point numbers in awk, unexpected results may occur due to the limitations of floating-point arithmetic. Floating-point numbers are stored in a binary format, which can cause inaccuracies in arithmetic operations, especially when adding or subtracting large or small numbers. Here are some tips to avoid unexpected results when working with floating-point numbers … Read more

Nginx Redirect Mobile / Smart Phone Traffic To Mobile Version Of the Web Site

To redirect mobile/smartphone traffic to the mobile version of a website using Nginx, you can use the if directive in your Nginx configuration file. Here’s an example configuration that redirects all mobile devices to a separate URL: server { listen 80; server_name example.com; root /var/www/example.com; if ($http_user_agent ~* ‘(iPhone|iPod|blackberry|android.*mobile|windows.*phone)’) { return 302 http://m.example.com$request_uri; } # … Read more

Linux: Log Everyone Out Of The System

To log everyone out of the system, you can use the kill command. To log out all users except yourself, you can use the following command: kill -HUP -1 To log out all users including yourself, you can use the following command: kill -HUP 1 Note that using this command will terminate all processes running … Read more

Unix: csh Shell Loop Example

In the csh shell, you can use a loop to perform a set of commands multiple times. Here are a few examples of loops in csh: For loop: #!/bin/csh set i = 1 while ( $i <= 10 ) echo “Iteration $i” @ i++ end This script will print “Iteration 1” to “Iteration 10”. For … Read more