How to Create a Timer in Bash

Linux Bash

Following my previous post on «How to Create a Prompt With Timeout in Bash », we will now see how to create a timer (countdown) in Bash using the built-in $SECONDS variable.

The $SECONDS variable holds in the number of seconds the script has been running. So it can easily be used to create a timer inside your script in Bash.

$ bash -c 'while true ; do echo -en "\r${SECONDS}s elapsed" ; sleep 1 ; done'
203s elapsed


How to Change config.json for Docker Mattermost Preview

Linux Docker Mattermost

These instructions show you how to change the config.json file for a Docker Mattermost Preview.

a- As root (or if you enabled non root users to manipulate docker), let’s open a shell in the docker container

docker exec -ti mattermost-preview /bin/bash

b. Update the APT db on the docker instance and install vim (needed to edit the file)

apt update
apt install vim

c. Change config_docker.json as needed

cd /mm/mattermost/config

vim config_docker.json

d. Restart the docker container

docker restart mattermost-preview

How to Change Forgotten Password on WSL (Bash for Windows)

Linux Bash Windows

So you have installed Bash for Windows, but forgot your password!! That’s easy to fix, and here’s how:

a. Find your username by running Bash for Windows and executing whoami

$ whoami

b. Change the default user to root by running the code below on a Windows command prompt (cmd.exe)

LxRun.exe /setdefaultuser root

c. Now change the password with bash -c 'passwd [user]' (also on the Windows command prompt)

bash -c 'passwd victor_m'
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

d. Change the default user back to your user

LxRun.exe /setdefaultuser victor_m

e. Profit