Author Archives: kenno

Remove trailing whitespace with VIM

Here’s a quick tip on how to get rid of unwated trailing whitespace using vim.

Let’s say, I have the following code:

Open that file with vim. The following command deletes any trailing whitespaces.


Here’s the screenshot of the text after removing the whitespace:

In search, \s finds whitespace (a space or tab). \+ finds one or more occurences. $ matches the end of line, finally e flag means no error is displayed.

Ref: Remove unwanted spaces (warning: this reference page contains lots of ads, probably avoid opening it on a mobile device.)

RHCSA’s Prep

At the end of last year, I took a training to prepare for Red Hat Certified System Administrator (RHCSA EX200) exam. Now it’s February and I haven’t taken the exam yet. Even worse, I forgot most of the things I learned during that 3 day training. Well, since I’m being chased to get this exam done ASAP, with a passing grade of course, I think now it’s the best time to start revising the material again. As part as the exam prep, I’m going to post small challenges and solutions.

I found a task of the day posted on CertDepot website, a very good resource to learn about Red Hat exam. So, let’s see if can I even do that. Here is the challenge:

Allowed time: 5 minutes.
Create a new user account called “bob” with password “redhat” and set expiration in one week.

My solution:

# man useradd
# useradd -e 2017-02-26 bob
# passwd bob

Time taken: 2 minutes 26 seconds.

I must admit the solution is not the most elegant, as I had to manually calculate 7th day’s date from today (2017-02-19).

Here’s another alternative solution according to this:

# useradd -e `date -d "7 days" +"%Y-%m-%d"` bob
# passwd bob

Another way to set the account expiry date is using chage.

# chage -E `date -d "7 days" +"%Y-%m-%d` bob
# chage -l bob
Last password change					: Feb 19, 2017
Password expires					: May 20, 2017
Password inactive					: never
Account expires						: Feb 26, 2017
Minimum number of days between password change		: 0
Maximum number of days between password change		: 90
Number of days of warning before password expires	: 7

How to toggle between buffers in Vim with vim-airline

First if you haven’t yet heard about vim-airline plugin, and you’re a Vim user, you owe it to yourself to check it out.

By default vim-airline displays the opening buffers on the top part of the window.

So how to navigate between those buffers? Well, according to this, it seems those buffers are for visual only. To navigate between them, we can use :bp for previous buffer, and :bn for next buffer. Alternatively, we can use :ls to list all buffers, then navigate to a particular buffer by running :number (substitute number with an actual number).

However, if you know any better or more elegant ways to switch between the opening buffers, please do share!

Changing a User’s Password on FreeBSD

Before getting into how to change a user’s password on FreeBSD, let’s have a quick revision on how that can be done on a Linux system.

As a user we can change the password by typing:

$ passwd
Changing password for user kenno.
Changing password for kenno.
Current password: 

Or with a root account, we can change/set the password for another user:

# passwd kenno
Changing password for user kenno.
New password: 

How about a FreeBSD? It should be the same way as how it’s done on Linux right? Right? Well, not quite.

On a FreeBSD system, in addition to run the passwd command, we also need to generate the password databases to be “in sync” with the plain text files.

# pwd_mkdb /etc/master.passwd

You can learn more about both passwd and pwd_mkdb, by running:

$ man passwd
$ man pwd_mkdb

Ref: Can’t change user password

FreeBSD 11 Blank Screen After Login via SLiM

After rebooting my FreeBSD 11.0, I wasn’t able to login to Mate desktop manager via SLiM (Login Manager).
I spent sometimes to try to fix it, but failed. I’ll try it again later when I have a bit of free time.

Here’s a quick note of a work around, so I won’t forget what I’ve done.

1) Disable loading slim on start up by editing /etc/rc.conf and commented out the following line:


2) Run this command manually to start mate-session:

$ xinit mate-session

So, it appears SLiM is the culprit here since Mate-session can be started up manually.

Zpool Not Automatically Mounted on Boot on Fedora

I love ZFS, but there is something that has annoyed me for quite sometimes – the zpool doesn’t get automatically mounted on boot. To work around this, I had to login as root and run:

# zpool import tank

to import tank pool before I login with my normal user account.

Well, I finally found a solution. This is what’s written on zfsonlinux/zfs WIFI about Fedora specifically:

Systemd Update:

When upgrading to the zfs- release it’s recommended that users manually reset the zfs systemd presets. Failure to do so can result in the pool not automatically importing when the system is rebooted.

systemctl preset zfs-import-cache zfs-import-scan zfs-mount zfs-share \

Okay, here’s how I fix my issue. First, ensure that a pool that I want to automatically mounted is manually mounted first. Then just run that lengthy command shown above:

# zpool import tank
# systemctl preset zfs-import-cache zfs-import-scan zfs-mount zfs-share zfs-zed
Created symlink /etc/systemd/system/zfs-mount.service.wants/zfs-import-cache.service → /usr/lib/systemd/system/zfs-import-cache.service.
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/zfs-import-cache.service.
Created symlink /etc/systemd/system/zfs-share.service.wants/zfs-mount.service → /usr/lib/systemd/system/zfs-mount.service.
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/zfs-mount.service.
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/zfs-share.service.
Created symlink /etc/systemd/system/zed.service → /usr/lib/systemd/system/zfs-zed.service.
Created symlink /etc/systemd/system/ → /usr/lib/systemd/system/zfs-zed.service.

Now, that makes me a much happier ZFS user!

Ref: zfsonlinux/zfs

របៀប​លុប​អត្ថបទ​ចម្រៀង​​ចេញ​ពី​ mp3

ខ្ញុំ​មាន​បទ​ចម្រៀង mp3 ពីរ​ឬបី​ដែល​មាន​អត្ថបទ​ចម្រៀង​ភ្ជាប់ជាមួយ (embedded lyric)។ ខ្ញុំ​ចង់លុប​អត្ថបទ​នោះចេញ។

នេះ​ជា​វិធី​មួយ​ដែល​អាច​សម្រេច​បំណង​ខាងលើ ដោយប្រើកម្មវិធី​ឈ្មោះ id3v2 នៅ​លើហ្វេដ័ររ៉ា។ ឧទាហរណ៍​ថា​ ចម្រៀង​ដែល​ខ្ញុំ​ចង់លុប​អត្ថបទភ្ជាប់​នោះ​ មាន​ឈ្មោះ​ថា “01 love you.mp3” ខំម៉ានដែល​យើង​ត្រូវ​វាយ ដូច​ខាង​ក្រោម​នេះ៖

$ id3v2 --remove-frame 'TEXT' 01\ love\ you.mp3
  • --remove-frame – លុប​ id3v2 frame
  • 'TEXT'

បើសិន​ជា​យើង​មាន​ mp3 ច្រើន​ក្នុង​ directory តែ​មួយ​ ហើយយើង​ចង់​លុប​​ ‘TEXT’ frame ចេញ យើង​អាច​ប្រើ​ខំម៉ាន​ដូច​នេះ៖

$ for i in *.mp3; do id3v2 -r 'TEXT' $i; done
Deleting Frame TEXT in file 01 love you.mp3 ...
Deleting Frame TEXT in file 02 Ima demo Aitai yo….mp3 ...
Deleting Frame TEXT in file 03 Brand New World.mp3 ...

សូម​កត់​សំគាល់​ថា ក្នុង​ខំម៉ាន​ខាង​លើ ខ្ញុំ​ប្រើ -r ជំនួស​អោយ​ --remove-frame។ អផសុន​ (options) ទាំង​ពីរ​នោះ វា​ដូច​គ្នា​ទេ៕

Install ZFS on Fedora 25 with kernel 4.8.13-300

After I had my Fedora 24 upgraded to 25 on my desktop, ZFS no longer worked. I tried to remove zfs package and reinstalled; it didn’t work.

Here’s how I got it working after trying many things. There could be a different way to fix it, though.

Let’s check the version of the kernel:

[root@sangkae ~]# uname -r

Check if spl, zfs are already installed:

[root@sangkae ~]# dnf info spl
Last metadata expiration check: 1:01:18 ago on Thu Dec 15 22:42:25 2016.
Installed Packages
Name        : spl
Arch        : x86_64
Epoch       : 0
Version     :
Release     : 1.fc25
Size        : 48 k
Repo        : @System
From repo   : zfs
Summary     : Commands to control the kernel modules
URL         :
License     : GPLv2+
Description : This package contains the commands to verify the SPL
            : kernel modules are functioning properly.

[root@sangkae ~]# dnf info zfs
Last metadata expiration check: 1:01:26 ago on Thu Dec 15 22:42:25 2016.
Installed Packages
Name        : zfs
Arch        : x86_64
Epoch       : 0
Version     :
Release     : 1.fc25
Size        : 808 k
Repo        : @System
From repo   : zfs
Summary     : Commands to control the kernel modules and libraries
URL         :
License     : CDDL
Description : This package contains the ZFS command line utilities.

Manually install spl, dkms:

# dkms install spl/
# dkms install zfs/

Load zfs module:

# modprobe zfs

Voilla, I got ZFS working again.

លុបចោលសម្លេងពីឯកសារ MKV

ឥឡូវនេះខែវិច្ឆិកាហើយ ប៉ុន្តែខ្ញុំមិនទាន់បាន​សរសេរ​អត្ថបទ​មួយឡើយ។ អញ្ចឹង គួរតែ​ចាប់ផ្តើម​មួយទៅមែន​ទេ?

ថ្ងៃនេះខ្ញុំចង់ចែករំលេករបៀបលុប audio track ចេញពីឯកសារ MKV ។ MKV ជា​ប្រភេទ​មួយ​នៃ​ហ្វមម៉ាត​របស់​ឯកសារ (file format) ដែល​យើង​អាច​ខ្ចប់​វីដេអូ សម្លេង និងសាប់ថាយថើល (subtitle)។ល។ ខ្ញុំមានឯកសារ MKV ដែលមានសំលេងពីរ ហ៊ីនឌី (Hindi) និងអង់គ្លេស ហើយ ខ្ញុំចង់លុបហ៊ីនឌីចេញ ដោយប្រើកុំព្យូទ័រជាមួយហ្វឺដរ៉ា (Fedora 24)។

ជាដំបូង យើងត្រូវបញ្ចូលប្រូក្រាមមួយជាមុនសិន។

# dnf install mkvtoolnix

ក្រោយពីបញ្ចូលប្រូក្រាមខាងលើ យើងអាចមើលថាតើមានអ្វីខ្លះនៅក្នុងឯកសារ MKV នោះ។

$ mkvmerge -i Sample.mkv
File 'Sample.mkv': container: Matroska
Track ID 0: video (MPEG-4p10/AVC/h.264)
Track ID 1: audio (MP3)
Track ID 2: audio (AAC)
Track ID 3: subtitles (SubRip/SRT)
Attachment ID 1: type 'image/jpeg', size 298984 bytes, file name 'Cover.jpg'

តាមលទ្ធផលខាងលើ យើងឃើញថាឯកសារនោះមានសម្លេងពីរ Track ID 1 និង Trakc ID 2។ អ្វីដែលយើងមិនអាចដឹងគឺ តើធ្រាក់មួយណាជាសម្លេងភាសាហ៊ីនឌី? យើងអាចប្រើប្រូក្រាម mplayer:

$ mplayer Sample.mkv
MPlayer 1.3.0-6.1.1 (C) 2000-2016 MPlayer Team

Playing Sample.mkv.
libavformat version 57.41.100 (external)
libavformat file format detected.
[aac @ 0x7fa06b3d4ac0]element type mismatch 1 != 0
[lavf] stream 0: video (h264), -vid 0
[lavf] stream 1: audio (mp3), -aid 0, -alang hin
[lavf] stream 2: audio (aac), -aid 1, -alang eng
[lavf] stream 3: subtitle (srt), -sid 0, -slang eng
[lavf] stream 4: video (mjpeg), -vid 1
VIDEO:  [H264]  1280x720  0bpp  23.976 fps    0.0 kbps ( 0.0 kbyte/s)

សម្លេងភាសាហ៊ីនឌី គឹជា Track ID 1 (mp3)។ យើងដកវាចេញ ដោយបង្កើតឯកសារថ្មីដោយគ្មានវា។

$ mkvmerge -o out.mkv --video-tracks 0 --audio-tracks 2 Sample.mkv
mkvmerge v9.2.0 ('Photograph') 64bit
'Sample.mkv': Using the demultiplexer for the format 'Matroska'.
'Sample.mkv' track 0: Using the output module for the format 'AVC/h.264'.
'Sample.mkv' track 2: Using the output module for the format 'AAC'.
'Sample.mkv' track 3: Using the output module for the format 'text subtitles'.
The file 'out.mkv' has been opened for writing.
Progress: 100%
The cue entries (the index) are being written...
Muxing took 0 seconds.
  • -o បង្កើតឯកសារថ្មី
  • --video-tracks ចម្លងវីដេអូត្រាក់លេខ
  • --audio-tracks ចម្លងសម្លេងត្រាក់លេខ
  • Sample.mkv ឧទាហរណ៍ឯកសារដើម

លទ្ធផលគឺ ឯកសារ out.mkv ដែលគ្មានសម្លេងភាសាហ៊ីនឌី។

Ref: Delete audio track from mkv file