Archive for the ‘Linux’ Category

Check MD5 hash of downloaded file in Linux

January 15th, 2020 No comments

Example, you’ve downloaded the latest Asus RT-AC56U firmware and want to check that the file is genuine. Copy the MD5-hash from the website.

echo 'b32190074e2133b8f6d779f3d6c779ef Downloads/RT-AC56U_3.0.0.4_382_51641-g46d2311.trx'|md5sum -c

You’ll get an OK if the file is genuine.

Categories: Bash, Linux, Ubuntu Tags:

Encode ripped music wav to mp3 using ffmpeg

January 6th, 2020 No comments

Example, sets bitrate to ~190kbit VBR.

ffmpeg -i IN.wav -q:a 2 OUT.mp3

Example, sets bitrate to 192kbit and cuts file after timestamp 4:17.

ffmpeg -i IN.wav -to 4:17 -ab 192k OUT.mp3
LAME Bitrate Overview
lame option Average kbit/s Bitrate range kbit/s ffmpeg option
-b 320 320 320 CBR (non VBR) example -b:a 320k (NB this is 32KB/s, or its max)
-V 0 245 220-260 -q:a 0 (NB this is VBR from 22 to 26 KB/s)
-V 1 225 190-250 -q:a 1
-V 2 190 170-210 -q:a 2
-V 3 175 150-195 -q:a 3
-V 4 165 140-185 -q:a 4
-V 5 130 120-150 -q:a 5
-V 6 115 100-130 -q:a 6
-V 7 100 80-120 -q:a 7
-V 8 85 70-105 -q:a 8
-V 9 65 45-85 -q:a 9


Categories: Bash, Linux, Ubuntu Tags:

Connect smb share HNAS in Ubuntu 18.04 shell

November 23rd, 2019 No comments
$ sudo mkdir /mnt/myfiles
$ sudo mount -t cifs //$ /mnt/myfiles -o username=USER\akkaid,vers=2.0
Categories: Bash, Linux, Ubuntu Tags:

Turn off screen on a Linux server

November 4th, 2019 No comments

If you have a Ubuntu Linux server and uses a laptop, you might want to close the lid and also turn off the backlight to preserve energy and lower heat. There is a command you can use to achive this. Use another computer and SSH to the server, then issue the following commands to turn off the TFT:

sudo apt install vbetool
sudo vbetool dpms off

If you want to turn the display back on, use:

sudo vbetool dpms on



Categories: Bash, Linux, Ubuntu Tags:

Remap one keyboard key in Ubuntu

October 15th, 2019 No comments

If you want to remap one key to another you can use the command xev to find the keycodes. Then remap by using the command xmodmap.

Let’s say you want to remap the key F5 to F4. This might be useful if you have a Kensington laser pointer and want to use the laser beam without issuing a F5-keypress that interrupts your PowerPoint or Google presentation. We first find the keycode for F5, which is 71, and then remap it.


KeyPress event, serial 34, synthetic NO, window 0x3c00001,
    root 0x191, subw 0x0, time 729495065, (926,341), root:(1055,472),
    state 0x0, keycode 71 (keysym 0xffc2, F5), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

KeyRelease event, serial 37, synthetic NO, window 0x3c00001,
    root 0x191, subw 0x0, time 729495169, (926,341), root:(1055,472),
    state 0x0, keycode 71 (keysym 0xffc2, F5), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False

The effect of the remap command is preserved until the next reboot.

xmodmap -e "keycode 71 = F4"

Keycode 56 is normally mapped to the “stop”-button on the Kensington remote to produce a ‘b’ for make the screen black during a presentation. This button can be reassigned to ‘k’ if you want to start a YouTube-video during a Google presentation.

xmodmap -e "keycode 56 = k"

When you want to restore the original keymappings, use code below.

xmodmap -e "keycode 71 = F5"
xmodmap -e "keycode 56 = b"


Categories: Bash, Linux, Ubuntu Tags:

Only “Dummy Output” sound device after sleep

October 5th, 2019 No comments

If you loses your sound output in Ubuntu 18.04 and is left with a “Dummy Output” only, you can try restarting pulseaudio. This might save you a reboot!

pulseaudio -k && sudo alsa force-reload

If this doesn’t fix the issue, and a reboot doesn’t fix it, go here for some more troubleshooting tips:

Categories: Bash, Linux, Ubuntu Tags:

Enable Hibernate in Ubuntu 18.04

September 12th, 2019 No comments


All credits goes to !

make it work with Ubuntu 18.04.

Make your /swapfile have at least the size of your RAM

sudo swapoff /swapfile
sudo dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo | grep MemTotal | grep -oh '[0-9]*') count=1024 conv=notrun
sudo mkswap /swapfile
sudo swapon /swapfile

Note the UUID of the partition containing your /swapfile:

$ sudo findmnt -no SOURCE,UUID -T /swapfile
/dev/nvme0n1p5 20562a02-cfa6-42e0-bb9f-5e936ea763d0

Reconfigure the package uswsusp in order to correctly use the swapfile:

sudo dpkg-reconfigure -pmedium uswsusp
# Answer "Yes" to continue without swap space
# Select "/dev/disk/by-uuid/20562a02-cfa6-42e0-bb9f-5e936ea763d0" replace the UUID with the result from the previous findmnt command
# Encrypt: "No"

Edit the SystemD hibernate service using sudo systemctl edit systemd-hibernate.service and fill it with the following content:

ExecStartPre=-/bin/run-parts -v -a pre /lib/systemd/system-sleep
ExecStartPost=-/bin/run-parts -v --reverse -a post /lib/systemd/system-sleep

Note the resume offset of your /swapfile:

$ sudo swap-offset /swapfile
resume offset = 34818

Configure Grub to resume from the swapfile by editing /etc/default/grub and modify the following line:

GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=20562a02-cfa6-42e0-bb9f-5e936ea763d0 resume_offset=34818 quiet splash"

Update Grub:

sudo update-grub

Update initramfs: sudo update-initramfs -u -k all

Create the following /etc/initramfs-tools/conf.d/resume:

RESUME=UUID=20562a02-cfa6-42e0-bb9e-5e936ea763d0 resume_offset=34816
# Resume from /swapfile

Update initramfs:

sudo update-initramfs -u -k all

Now you can hibernate with sudo systemctl hibernate.

One can also create those scripts:

    sudo tee /usr/local/bin/gotosleep <<EOF
    dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
    sleep 2
    sudo /usr/sbin/s2both
    sudo chmod +x /usr/local/bin/gotosleep
    sudo tee /usr/local/bin/gotohibernation <<EOF
    dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
    sleep 2
    sudo systemctl hibernate
    sudo chmod +x /usr/local/bin/gotohibernation

So you can sleep with gotosleep or hibernate with gotohibernation.

You must be able to execute sudo s2both, sudo s2ram and sudo systemctl hibernatewithout having to enter your password for the previous scripts to work.

You could do that for example by creating a powerdev group, add your current user to it, and configure the following sudoers config (edit it with sudo visudo -f /etc/sudoers.d/powerdev):

     %powerdev ALL=NOPASSWD: /usr/sbin/s2both, /usr/sbin/s2ram, /bin/systemctl hibernate

Documentation used:

Add ‘Hibernate’ Option in Power Menu in Ubuntu 18.04


sudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla

When the file opens, paste following content and save it.

[Re-enable hibernate by default in upower]

[Re-enable hibernate by default in logind]

Install the Gnome connector:

sudo apt-get install chrome-gnome-shell

Open Firefox, press CTRL+SHIFT+a, and install the “GNOME Shell integration” Add-On. Link to the add-on:

Go to and search for “Hibernate Status Button“, or click this link: Turn “ON” the extension in the upper right corner.

Restart your computer and enjoy the new hibernate-button in the shut-down dialog!

For those who never installed a gnome extension, see this how to tutorial for details.

Categories: Bash, Linux, Ubuntu Tags:

How to Change Lid Close Action in Ubuntu 18.04 LTS

September 5th, 2019 No comments

Open terminal by pressing Ctrl+Alt+T or searching for “Terminal” from start menu. When it opens, run command:

sudo gedit /etc/systemd/logind.conf

When the files opens, uncomment the line #HandleLidSwitch=suspend by removing # in the beginning, and change the value to:

  • HandleLidSwitch=poweroff, shutdown / power off when lid is closed.
  • HandleLidSwitch=hibernate, hibernate when lid is closed (need to test if hibernate works).
  • HandleLidSwitch=ignore, do nothing.
  • HandleLidSwitch=suspend, suspend laptop when lid is closed.

Save the file and finally restart the Systemd service to apply changes via command:

systemctl restart systemd-logind.service
Categories: Bash, Linux, Ubuntu Tags:

Reboot linux at specific time

August 13th, 2019 No comments

Sometimes you want to reboot a server in the middle of the night. With linux it’s as simple as this command:

shutdown -r 04:00

Which will reboot the machine at 4 am in the morning. If you need to abort the reboot, use the following to abort the reboot:

shutdown -c
Categories: Bash, Linux, Red Hat / CentOS, Ubuntu Tags:

Mount exFAT in Ubuntu 18.04

August 8th, 2019 No comments

The exFAT file system is created by Microsoft to overcome the 4GB file size limit in FAT. To mount such an partition you need to enable exFAT. Otherwise you’ll get an error saying can’t mount unknown filesystem type “exfat”. In Ubuntu 18.04 it’s simple, just open a terminal and type:

sudo apt install exfat-fuse exfat-utils

If this doesn’t work you might need to add the “universe” repository first. Here’s an example followed by a mount of the device at /dev/sdb1. Replace this device with your own device:

sudo add-apt-repository universe
sudo apt update
sudo apt install exfat-fuse exfat-utils
sudo mkdir /mnt/myEXFAT
sudo mount /dev/sdb1 /mnt/myEXFAT

To list devices and their partitions, use the command:

sudo parted -l

Beware that exFAT can’t handle certain characters in the file names, like “:”. If you need to rename multiple file names you can modify the below example that replaces all “:”-characters with an underscore “_” in the current directory:

find . -depth -maxdepth 1 -name '*:*' -execdir bash -c 'mv -- "$1" "${1//:/_}"' bash {} \;

Categories: Bash, Linux, Ubuntu Tags: