I call this the unofficial bash strict mode. This causes bash to behave in a way that makes many classes of subtle bugs impossible. You’ll spend much less time debugging, and also avoid having unexpected complications in production.
Source: Use the Unofficial Bash Strict Mode (Unless You Looove Debugging) (aaron maxwell)
Use iptables to create a VPN killswitch to protect against data leaks.
If you’re connected to a VPN, you need a killswitch. No, it’s not as metal as it sounds. It’s just a mechanism that stops your Internet connection when you’re disconnected from the VPN. It protects you from inadvertently leaking sensitive information onto the Internet when the VPN connection drops.
Source: How To Create A VPN Killswitch Using Iptables on Linux – LinuxConfig.org
The ls command is used to list directory contents and the results can be sorted upon several criteria such as by date, alphabetical order of filenames, modification time, access time, version and file size.
In this article, I will show you how to sort files by date using ls command in Linux.
Source: Guide to Sort Files by Date Using LS Commandline in Linux (LinOxide)
Bing has several search engine shortcuts and advanced features that can be used to get better and accurate search results. These Bing search tips and tricks will help you narrow down search results to find exactly what you are looking for.
Source: 23 Advanced Bing Search Tips And Tricks You Should Know (Fossbytes)
Ever wondered why programming in Bash is so difficult? Bash employs the same constructs as traditional programming languages; however, under the hood, the logic is rather different.
Source: Understanding Bash: Elements of Programming | Linux Journal
I knew that day that the Shortcuts app has paved the way for automation in iPhone, but I didn’t realize that it can also be used to keep a track on the proliferating police abuse.
Source: This Siri Shortcut Automatically Triggers Camera Every Time Cops Pull You Over (Fossbytes)
Every so often something really useful appears on Reddit, and this is such a case. You may encounter a situation where you want to execute the contents of a bash script, but not more frequently than every few seconds. A Reddit user wanted to know How to check if a command in .bashrc has been executed within last 10 seconds if yes don’t execute the command again. The response by Reddit user mdaffin is brilliant in its simplicity, and can be used in any bash script where you don’t want the contents executed too often:
Write a time stamp to some file, check said file before you run the command if now – timestamp > 10s run the command and update the timestamp.
EDIT: Like this (with modification times instead):
if [[ ! -f "$TS_FILE" ]] || [[ "$(expr "$(date +%s)" - "$(stat -c %Y "$TS_FILE")")" -gt 10 ]]; then
You’d replace the
echo "running" line with the part of the bash script you want to run only if it’s been 10 seconds since the last time the script was run, or whatever number of seconds you specify after the
-gt. If the bash script actually outputs a file as part of its normal operation then you could specify that file in the
TS_FILE= line; there would be no need to create a separate timestamp file (unless some other process could also modify that same file).
This doesn’t actually stop the bash script from running; it just prevents it from executing the part of the script that you don’t want executed too frequently. This could be very useful in a situation where without such protection, the too-frequent execution of the script might cause something undesirable to happen (such as getting locked out of an online site for hammering it with requests). Depending on the situation there may be other, perhaps even better ways to avoid this possibility, but in other cases this may indeed be the best approach.
Grepping is awesome, as long as you don’t glob it up! This article covers some grep and regex basics.
Source: Globbing and Regex: So Similar, So Different | Linux Journal
SSH-key-based authentication provides a more secure alternative to password-based authentication. In this tutorial we’ll learn how to set up SSH key-based authentication on a Debian 9 installation.
Source: How to Set Up SSH Keys on Debian 9 | DigitalOcean
Some websites don’t allow copying and pasting into input fields. Use this add-on to enable copying and pasting at sites that don’t allow it.
Source: Unblock Copy and Paste in Chrome and Firefox | Gizmo’s Freeware