Skip to content

Posts from the ‘Linux Quick Tips’ Category


Log MySQL Queries

If you want to log MySQL Queries log in to your mysql client and run:

mysql> SHOW VARIABLES LIKE "general_log%";
| Variable_name    | Value                 |
| general_log      | ON                    |
| general_log_file | /var/db/mysql/machine.log |
2 rows in set (0.00 sec)
mysql> SET GLOBAL general_log = 'ON';
Query OK, 0 rows affected (0.00 sec)

Then to see the queries as soon as they run do tail on the log.

tail -f /var/db/mysql/machine.log

After you’ve seen the queries and you’ve completed the debug task it is a good practice do disable logging:

mysql> SET GLOBAL general_log = 'OFF';
Query OK, 0 rows affected (0.02 sec)

Check if a Service is Running Using Telnet and How to Quit Telnet Session

Telnet is not used that much anymore. To connect to a managed switch CLI this could be your only options. But then telnet has other use: you can check if a service run on a port on a remote machine.

For example to check if mysql server is running on a remote machine:

 # telnet 3306
Connected to
Escape character is '^]'.

To check if ssh is running on a remote machine:

 # telnet 22
Connected to
Escape character is '^]'.
Protocol mismatch.
Connection closed by foreign host.

You should get some reply from the remote machine with a text.

If you get no reply that means either that the service is not running or the service is running on other port (in case of SSH) or that the remote machine’s firewall blocks the access from outside to that service.

Now, if you want to quit telnet you will notice Ctrl + C is not working.

In order to quit telnet press Ctrl + ] to get to telnet console then type: quit


Find Out the Version of Your Ubuntu Linux

To find out which version is the Ubuntu Linux installed on your machine you must use the lsb_release command:

# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 17.04
Release:	17.04
Codename:	zesty

Configure Networking in Ubuntu 16.04 Server

One way on some Ubuntu versions was to edit /etc/network/interfaces and add the the configuration of network interface. On Ubuntu 16.04 I’ve don the following setup:

# cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d

And then we create a file in /etc/network/interfaces.d called enp0s3:

# cat enp0s3
auto enp0s3
iface enp0s3 inet static
  post-up route add default gw
  pre-down route del default gw

Rename Multiple Files in Linux

To rename multiple files in Linux run from the command line:

for f in *.cc; do mv -- "$f" "${}.cpp"; done

Previous command will rename all .cc files into .cpp files.

Note: It will not work recursively. To rename recursively use the following command:

find ./ -type f -exec rename 's/.mm/.cpp/' '{}' \;

Add an user to Ubuntu Linux from command line

If you want to add an user to your Ubuntu Linux machine here is what you need to do. Login as root (or use sudo) and then run (as root):

useradd -d /home/john -m john
passwd john
usermod -aG sudo john

If you are not root run:

sudo useradd -d /home/john -m john
sudo passwd john
sudo usermod -aG sudo john

In our example john is the user we want to add. Last command (usermod) will allow our user to run root commands via sudo.


Becoming root on Ubuntu Linux

If you are using Ubuntu Linux you’ve logged in as an user. If you want to become root so you won’t have to input sudo on every command you run, here’s what you need to do:

sudo su


sudo su -

which is probably what you really want. su – will invoke a login shell after switching the user. Just running su with no parameters will just switch the user (keeping the old shell and environment variables).

You can also run:

sudo -i

Then you get the root prompt and you will be able to run any command as root.


Dealing with “Bad: new password is too simple” issue on Ubuntu Linux

Let’s say you’ve booted with Live Ubuntu CD/DVD and you want to change the password of your user which is called ubuntu on Live Ubuntu CD/DVD. If you run:


you might get an error like:

You must choose a longer password


Bad: new password is too simple.

You can bypass those checks by running passwd as a root with sudo:

sudo passwd

That way you will be allowed to enter short or too simple passwords which sometimes you need for testing purposes. Of course you will not use such passwords on machines connected to the internet but maybe only on test machines, maybe in virtualized environments.


Installing VirtualBox Guest Additions on Ubuntu Linux Guest

If you want to install VirtualBox Guest Additions on Ubuntu Linux Guest here what you need to do.

First go to VirtualBox -> Devices and click on Insert Guest Additions CD Image.

From the terminal look where the image is mounted. Usually it is under:


where username is your username used to login to your machine.

Then we need to install some packages:

sudo apt-get update
sudo apt-get install build-essential linux-headers-$(uname -r)

Then we run the script from the CD image:

cd /mnt/username/VBOXADDITIONS_5.0.18_10667
sudo ./

You need to run this script after every kernel update.


Fixing: apt-get install mc is not available error on Ubuntu

So you’ve just installed Ubuntu 16.04, you’ve configured networking and it works properly but when you want to install Midnight Commander (or other package) you get an error:

apt-get install mc is not available

To fix the problem run first apt-get update command:

sudo apt-get update

Then try to install mc:

sudo apt-get install mc

Of course there could be other reasons (like your /etc/apt/sources.list file missing or containing wrong links to package repos) but on a default Ubuntu installation this could fix the problem).