In Vim, ’20G’ moves the cursor to line 20 in command mode. But how to move the cursor to a specific byte in Vim? In normal mode, 20go will move the cursor to byte 20. Or in command line, :goto 20 or :go 20 From vimdoc: :[range]go[to] [count] [count]go Go to {count} byte in the
Read more
Category: QA
Questions and answers.
How to install MATE on Linux Mint 17 Qiana?
Posted onI am using Linux Ming 17 Qiana. How to install MATE on Linux Mint 17? In Linux Mint, the package that installs MATE is ‘mint-meta-mate’: $ sudo aptitude install mint-meta-mate
How to enable natual scroll of touchpad in MATE on Linux?
Posted onThere are options for Gnome 3 and Cinnamon to make touch pad “natual scroll”. But in MATE, there is no such options in its “Mouse” control options. How to enable natual scroll of touchpad in MATE on Linux? You may manually set the change of your ‘scrolls’ from the touch pad to negative values using
Read more
How to get a user’s home directory from the username in a variables in Bash?
Posted onIn Bash, ~username gives the username user’s home. However, this does not work for situations where username is in a variable such as ~$user How to get the home directory from the user name in a variable in Bash? You can use this Bash script snippet: userhome=$(eval echo ~$user) Here, $user get evaluated to its
Read more
How do I force Linux to unmount a filesystem?
Posted onSome time, Linux fails to unmount a filesystem reporting “device is busy”. I understand that this helps avoid data lost by disallowing unmouting a filesystem when it is being used. But for some situations, I am sure there is something wrong happened or I care not data lost, such as a NFS mounting while the
Read more
In Vim, how to search and replace in visual selection?
Posted onSearch and replace in the whole text in Vim can be done by :%s/from/to/gc. But how to search and replace in visual selection only? The %V atom in Vim restricts a pattern so that it matches only inside the visual selection. So, your command for searching and replacing only in the visual selection can be
Read more
How to generate a CSR from a private SSL key?
Posted onI am renewing my SSL key for my websites. The CA requests a CSR. I have my private key. How to generate a CSR (Certificate Signing Request) from a private SSL key? You can generate a CSR from your private key with openssl: openssl req -new -key ssl.key -out req.pem Here, ssl.key is your private
Read more
How to manually set Vim’s filetype?
Posted onVim can detects the file types from quite well. But under certain situations, such as creating a new file, Vim does not automatically set the file type. How to manually set it? In side Vim, to set a filetype, set value to the filetype variable. For example, to set the filetype to php: :set filetype=php
How to get the top committers in git?
Posted onHow to get the top committers in git? Like in github: But plain text is fine showing number of commits and author names/emails sorted by the number of commits. You may use this command: git log | grep Author | sort | uniq -c | sort -n -r Here, count the number of commits by
Read more
Linux boots failed with “sulogin: can not open password database” while the /etc/passwd and /etc/shadow files look fine
Posted onLinux boots failed with “sulogin: can not open password database” while the /etc/passwd and /etc/shadow files look fine. How to fix this? The OS is Fedora 22. You may try this trick Step 1: boot Linux with rw init=/bin/bash following this tutorial. Step 2: after Linux booted, disable SELinux following this tutorial. Reboot. If it
Read more
How to transfer text messages from android to computer?
Posted onHow to transfer text messages from android phone to computer? One solution is to use the SMS Backup & Restore app. The app will backup your messages to a microSD card and then you can copy it out to a PC by connecting your Android phone to your PC with the USB cable.
How to get the latest git commit SHA-1 in a repository?
Posted onHow to get the latest git commit SHA-1 id in a repository? And how to get the first 8 digits of the SHA-1? Instead of the method introduced here, you may use $ git rev-parse HEAD to get the commit SHA-1 hash ID. If you want to get the first 8 digits only, use $
Read more
How to debug media print view of Web page in Firefox?
Posted onHow to debug the media print view set by @media print {} in CSS of Web pages in Firefox? In firefox, after opening the Web page, First, hit “Shift + F2” to open the “Developer Toolbar” at the bottom. Second, in the “Developer Toobar”, input media emulate print and Firefox will show the print view
Read more
How to sort lines by length in Linux?
Posted onI have a text file with many lines of text. In Linux, how to sort the lines by their length? You can make use of awk together with the sort program like awk ‘{ print length(), $0 | “sort -n” }’ /path/to/text/file Here, we use awk to calculate the text length and sort -n to
Read more
How to make journalctl faster?
Posted onOn Linux, I check system logs by journalctl. But it is soooo slow. How to make it faster. By default without any options, the journalctl is indeed very slow. But usually, we are only interested in some logs and can use options to specify the logs that we are interested to check. This will make
Read more
How to play video in full screen and keep it looping with MPlayer?
Posted onI would like to play a video file in full screen and automatically make it keep playing during an exhibition. On Linux, how to do it with MPlayer? You can use this command mplayer -fs -loop 0 video.mp4 Here, -fs make it fullscreen and -loop 0 makes it loop infinitely. For more usage of mplayer,
Read more
How to do “contains string” test in Bash?
Posted onHow to test whether a string $str contains another string $needle in Bash? You can use this piece of Bash script: [[ “$str” == *”$needle”* ]] A usage example: $ str=”abcde hello” $ needle1=”deh” $ needle2=”de hello” $ [[ “$str” == *”$needle1″* ]] && echo “matched” $ [[ “$str” == *”$needle2″* ]] && echo “matched”
Read more
‘dd’ command cannot support calculation for its parameters
Posted on$ dd if=/dev/zero of=./4Ktest100M bs=4KB count=25000*9 dd: invalid number `25000*9′ I think ‘dd’ should support calculation for its parameters like ‘bs’, ‘count’ and so on. You can get the effect by using some other tools/commands, like dd if=/dev/zero of=./4Ktest100M bs=4KB count=$((25000*9)) or dd if=/dev/zero of=./4Ktest100M bs=4KB count=$(bc <<< 25000*9) I think it makes sense. Thank
Read more
How to remove trailing / in path in Bash?
Posted onI am writing a Bash script accepting input of a path from the user. I want to make the path have no trailing ‘/’, such as ‘/path/to/dir’ instead of ‘/path/to/dir/’. However, as the input is from the user, the input could be ‘/path/to/dir’. My script is intended to handle this. The question is: how to
Read more
Why are keys overlap in SST files at Level 0 in LevelDB system?
Posted onAs is known, keys may be overlap in SST files of level 0 in LevelDB. I am wondering why it needs to be overlap? An sstable is read-only after being written to the disk from a memtable. Accumulated K/Vs in the log up to a certain size are organized as a memtable and written to
Read more