Bash Script: Find Out In What Directory Script Is Stored Under Unix Or Linux

You can use the following line of code in a bash script to determine the directory in which the script is stored: SCRIPT_DIR=”$(cd “$(dirname “$0″)” && pwd)” Here’s how it works: dirname “$0” returns the directory component of the script’s file path. cd “$(dirname “$0″)” && pwd changes to the directory and prints the absolute … Read more

HowTo: Bash Shell Split String Into Array

You can split a string into an array in bash using the IFS (Internal Field Separator) variable and parameter expansion. Here is an example of how to split a string into an array: string=”one two three four” IFS=’ ‘ read -ra arr <<< “$string” for i in “${arr[@]}”; do echo “$i” done In this example, … Read more

HowTo: Bash Extract Filename And Extension In Unix / Linux

You can extract the filename and extension from a file path in bash using parameter expansion and string manipulation. Here are a few examples of how to extract the filename and extension: Extract the filename and extension using parameter expansion: path=”/path/to/file.ext” filename=”${path##*/}” extension=”${filename##*.}” echo “Filename: $filename” echo “Extension: $extension” Extract the filename and extension using … Read more

Debian / Ubuntu Linux: Install Cherokee Web Server

To install the Cherokee web server on Debian/Ubuntu Linux, you can follow these steps: Add the Cherokee repository to your system’s repository list: echo “deb http://www.cherokee-project.com/deb/ $distro $arch” | sudo tee /etc/apt/sources.list.d/cherokee.list where $distro is your Debian or Ubuntu distribution (e.g. bionic, focal, xenial, etc.) and $arch is your system architecture (e.g. amd64, i386, etc.). … Read more

Linux Configure Firewall Using Shorewall Under RHEL / CentOS

To configure a firewall using Shorewall under Red Hat Enterprise Linux (RHEL) / CentOS, you can follow these steps: Install Shorewall: yum install shorewall Start the firewall and enable it to start at boot: systemctl start shorewall systemctl enable shorewall Configure the firewall rules: Shorewall rules are stored in the following files: /etc/shorewall/policy: contains the … Read more

HowTo: grep All Sub-directory For Files

To search all subdirectories for files using grep you can use the following command: grep -r pattern directory where pattern is the search string and directory is the top-level directory to search. The -r or –recursive option tells grep to search recursively through subdirectories. For example: grep -r “error” /var/log This will search for all … Read more