Home avatar

Building and implementing end-to-end solutions to solve real-world problems

Timing Shell Commands in Bash

When working in a Unix-like environment, timing the execution of shell commands is a useful way to measure the performance of various operations. Bash provides a couple of approaches for timing shell commands: using the /usr/bin/time command or setting the TIMEFORMAT variable.

Using /usr/bin/time Command

The /usr/bin/time command is a versatile utility that can provide information about the resources used by a process, including the execution time. To time a command using /usr/bin/time, you can use the following syntax:

Unanttended Upgrade Docker

To configure unattended upgrades for Docker on a Debian-based system, you can add the following line to the 50unattended-upgrades file. This will ensure that Docker packages are automatically updated when unattended-upgrades runs.

Here are the steps to do this:

  1. Open a terminal on your Debian-based system.

  2. Use a text editor to open the 50unattended-upgrades file for editing. You’ll typically find this file in the /etc/apt/apt.conf.d/ directory.

1
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
  1. Add the following line to the file, which specifies that Docker packages should be automatically upgraded:
1
2
3
4
5
Unattended-Upgrade::Allowed-Origins {
    "${distro_id}:${distro_codename}-security";
    "${distro_id}:${distro_codename}-updates";
    "Docker:${distro_codename}";
};

This configuration tells unattended-upgrades to include the Docker repository for automatic updates, in addition to the security and regular updates repositories for your distribution.

Removing Orphaned Packages on Debian/Ubuntu With Deborphan

When you install and remove packages on a Debian-based Linux distribution like Debian or Ubuntu, sometimes you end up with orphaned packages - packages that were installed as dependencies for other software but are no longer needed. These orphaned packages can take up disk space and clutter your system. One tool that can help you identify and remove these orphaned packages is Deborphan.

What is Deborphan?

Deborphan is a command-line tool for identifying and removing orphaned packages on Debian-based systems. It analyzes the package dependencies and checks which packages are no longer required by any other installed packages. Once it identifies these orphaned packages, you can choose to remove them, freeing up disk space and keeping your system clean.

Enabling Root as Default User in WSL on Windows 10

If you want to set the default user in Windows Subsystem for Linux (WSL) to “root” instead of your regular user, you can achieve this using PowerShell or by modifying the WSL configuration file. Please note that running WSL as the root user is generally not recommended for security reasons, as it can expose your system to potential risks. Proceed with caution and only if you have a valid reason for doing so.

Git Patch Applying and Creating Patches in Git

In Git, patches are a way to capture and apply changes made to a codebase. They can be useful for sharing changes between developers or for applying changes across different branches. In this article, we’ll explore how to create and apply patches in Git.

Creating Patches

Patching Non-Staged Files

To create a patch for changes that have not been staged yet, you can use the following command:

Vim Search and Replace String

Vim is a powerful text editor that offers various functionalities for searching and replacing strings within your text. Here are different ways to perform string replacements using Vim’s command mode:

Replace String on Selected Line

To replace a string on the currently selected line, you can use the :s command. For instance, to replace all occurrences of “foo” with “bar” on the selected line, you can use the following command: