Exponential search is an algorithm designed to search for a target value in a sorted array. It is useful in scenarios when dealing with large or potentially infinite datasets and it can also help you find a number, which is not known in advance. Let’s see how it works and how to implement exponential search in bash.
Continue readingCategory: Tutorials
Linux tutorials with focus on shell scripting and monitoring. Here you will find texts about solving real world problems with code examples.
dealing with float numbers in bash
Dealing with float numbers in bash can be a bit tricky since bash natively supports only integer arithmetic. However, you can perform floating-point arithmetic using external tools. Here we will walk through few methods to handle floating-point numbers in bash.
Continue readingloops in Linux shell scripts
Loops in Linux shell scripts is something you will inevitably face once writing more complex scenarios. They are nothing new for those who have at least some sort of programming experience, since they exist in pretty much any programming language. Loops are control structures to repeatedly execute a block of code as long as a specified condition is true. They are essential for automating repetitive tasks and processing large amounts of data efficiently. Since loops are a fundamental programming concept, they of course exist in bash (or any other shell).
Continue readingcheck ownership and permissions for absolute path easily
I couldn’t count times when asking someone to check permissions in Linux for some file I was given answer which was something like:
[root@linux ~]# ls -l /var/log/httpd/access_log
-rw-r--r-- 1 root root 17245040 Mar 13 13:38 /var/log/httpd/access_log
[root@linux ~]#
So all looks good – file is readable. But is it really?
Continue readingredirect both stdout and stderr to same place
Sometimes you might want to redirect both stdout and stderr to same place. You can do it like:
[root@linux ~]# ./script.sh >/dev/null 2>&1
But there is a shorter way…
Continue readingfew useful commands while searching for files / patterns in files
Searching for files or patterns in files occurs quite frequently when dealing with CLI daily. Search for files in Linux is one of the essential skills to have while administrating servers. Here are few useful commands for fast implementation of such tasks.
Continue readingshorthand if – else in bash
For some simple if-else conditions you may want to avoid having whole if; then; else; fi type of code. Instead, you can do it all in one bash if shorthand line. Here is how.
Continue reading“Hello World” in bash
Let’s suppose that you have just opened Linux terminal for the first time in your life. Your wish is to write nothing but bash “hello world” type of thing. As this command is one-liner, you can simply do this:
Continue reading