---
# System prepended metadata

title: Ubuntu 18.04 雜記
tags: [ubuntu]

---

---
tags: ubuntu
GA: UA-167433668-1
title: Ubuntu 18.04 雜記
description: 記錄我使用Ubuntu 18.04時所作的一些系統設定變更&常常忘記的東西…
---

Ubuntu 18.04 雜記
===
記錄我使用Ubuntu 18.04時所作的一些系統設定變更&常常忘記的東西…


## 一些常用鍵盤快捷鍵
星號標記^★^是我有修改/自己新增的設定！
| 動作 | 快捷鍵|
| - | - |
| (中文輸入法)打特殊字元| <kbd>\`</kbd> |
| 部份截圖並複製到剪貼簿| <kbd>win</kbd>\+<kbd>shift</kbd>\+<kbd>S</kbd>^★^  |
| 預覽視窗^★^| 用滑鼠中間鍵點擊Dock Icon |
| 切換上/下workspace| <kbd>win</kbd>\+<kbd>pgup</kbd> / <kbd>win</kbd>\+<kbd>pgdn</kbd>  |
| 把目前視窗丟去上/下workspace| <kbd>shift</kbd>\+<kbd>win</kbd>\+<kbd>pgup</kbd> / <kbd>shift</kbd>\+<kbd>win</kbd>\+<kbd>pgdn</kbd> |
| 縮小視窗 | <kbd>win</kbd>\+<kbd>H</kbd> |
| toggle maximize window vertically| <kbd>ctrl</kbd>\+<kbd>win</kbd>\+<kbd>↑</kbd> ^★^ |
| toggle emoji keyboard | <kbd>win</kbd>\+<kbd>shift</kbd>+<kbd>E</kbd> ^★^ |


## 注音輸入法 (ibus-chewing)

- 輸入全形標點符號是<kbd>shift</kbd>+<kbd>\<key\></kbd>

選詞的時候把詞「切開」
例如：想打「飛機」的話，打「ㄈㄟ﹉ㄐ一﹉」會出現「飛機」。當光標移到「飛」和「機」中間並按下`↓`的時候，卻無法單獨為「ㄐ一﹉」選字，反而會自動跳到「飛」的前面，而且選項只有「飛機」。
- **方法1:**
光標移到兩字的中間，按`tab`就可以單獨為後面的字進行選字
- **方法2:**
光標移到兩字的中間，按`↓`的時候會被「彈」去前面選**詞**，這時候再按一次`↓`就可以單獨為後面的字進行選字

兩種都有一個**共通缺點**：有時候前面的字會跑掉...例如：想打「非長」的話，打了「ㄈㄟ﹉ㄔㄤˊ」會出現「非常」。當你用上述任一方法把詞切斷並把第二個字選擇「長」的時候，第一個字會自己變成「ㄈㄟ﹉」的首選字「飛」，於是變成「飛長」…

## 點擊Dock icon縮小目前視窗
GUI到處找都找不到，只好上網查，馬上找到這篇 [Click on Icon to Minimize Application in Ubuntu 18.04](https://tipsonubuntu.com/2018/04/15/click-icon-minimize-application-window-ubuntu-18-04/) 
前面說一大堆要安裝什麼dconf編輯器的，其實根本不用！看到最後才說，只要執行下面這一行指令就好了 :+1: 
`$ gsettings set org.gnome.shell.extensions.dash-to-dock click-action 'minimize'`
:::warning
這個作法的問題是如果同個app有超過1個正在運行的視窗，click他的dock icon只會直接把目前視窗縮小，沒辦法像在windows一樣預覽/選擇視窗…
:::

順便說, `$ gsettings list-keys org.gnome.shell.extensions.dash-to-dock` 可以看到一大堆可以調整的設定，[這裡](https://github.com/micheleg/dash-to-dock/blob/master/schemas/org.gnome.shell.extensions.dash-to-dock.gschema.xml)可以看到acceptable parameters(?)
~~改天來研究看看有沒有辦法可以預覽視窗…~~
> [這裡](https://github.com/micheleg/dash-to-dock/pull/574)可以看到是有人想做這個feature, 但目前還沒做出來就是了… [time=24 May 2020]

## Hover預覽視窗

以下作法雖然沒辦法像windows一樣preview on hover, 但至少還是可以preview, 只不過要用中間鍵點擊... 
```
$ gsettings set org.gnome.shell.extensions.dash-to-dock middle-click-action 'previews'
```

## Emoji keyboard

Install from [here](https://extensions.gnome.org/extension/1162/emoji-selector/).
To install gnome extensions directly from the website, the **plugin** and **connector** must be installed first.
Plugin (firefox): [here](https://wiki.gnome.org/Projects/GnomeShellIntegrationForChrome)
Connector: `sudo apt install chrome-gnome-shell`
Default keyboard shortcut to toggle emoji selector is <kbd>win</kbd>+<kbd>E</kbd>.

> [time=27 Jun 2020]


## 系統字體
一般來說比較簡單的方法是用`gnome-tweak-tool`但是我不想單純為了改字體就安裝一個新的東西 :unamused: 
用`gsettings`也可以改，但有些地方還是改不到，例如畫面最上方的狀態欄
```
$ gsettings set org.gnome.desktop.interface font-name 'URW Gothic L Book 11'
$ gsettings set org.gnome.desktop.interface document-font-name 'URW Gothic L Book 11'
$ gsettings set org.gnome.desktop.wm.preferences titlebar-uses-system-font false
$ gsettings set org.gnome.desktop.wm.preferences titlebar-font 'URW Gothic L Book 11'
$ gsettings org.gnome.nautilus.desktop font 'URW Gothic L Book 11'
```

> [time=7 Oct 2020]


## 讓移動子視窗不會連大視窗一起動

[參考](https://askubuntu.com/questions/972276/how-do-i-move-child-windows-without-moving-or-minimizing-parent-in-gnome-3)
```
$ gsettings set org.gnome.shell.overrides attach-modal-dialogs false
$ gsettings set org.gnome.mutter attach-modal-dialogs false
```

## 避免syslog被discord塞爆
參考：[snapcrafters/discord/issue#23](https://github.com/snapcrafters/discord/issues/23)
discord有個功能是會顯示你正在玩什麼遊戲or聽什麼音樂，為了這個功能他會每5秒去掃proc
但是snap預設是不會允許這種動作的(掃proc)所以就會吐一堆error進syslog，像這樣(樣本log取自於[這](https://github.com/snapcrafters/discord/issues/23#issuecomment-530962784))
```
[11016.951629] audit: type=1400 audit(1568315092.037:149127): apparmor="DENIED" operation="ptrace" profile="snap.discord.discord" pid=18216 comm="Discord" requested_mask="read" denied_mask="read" peer="unconfined"
[11016.951656] audit: type=1400 audit(1568315092.037:149128): apparmor="DENIED" operation="open" profile="snap.discord.discord" name="/proc/2027/cmdline" pid=18216 comm="Discord" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
[11016.951670] audit: type=1400 audit(1568315092.037:149129): apparmor="DENIED" operation="open" profile="snap.discord.discord" name="/proc/2043/cmdline" pid=18216 comm="Discord" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
[11016.951680] audit: type=1400 audit(1568315092.037:149130): apparmor="DENIED" operation="ptrace" profile="snap.discord.discord" pid=18216 comm="Discord" requested_mask="read" denied_mask="read" peer="unconfined"
[11016.951698] audit: type=1400 audit(1568315092.037:149131): apparmor="DENIED" operation="ptrace" profile="snap.discord.discord" pid=18216 comm="Discord" requested_mask="read" denied_mask="read" peer="unconfined"
[11016.951722] audit: type=1400 audit(1568315092.037:149132): apparmor="DENIED" operation="open" profile="snap.discord.discord" name="/proc/2178/cmdline" pid=18216 comm="Discord" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0
[11016.951731] audit: type=1400 audit(1568315092.037:149133): apparmor="DENIED" operation="ptrace" profile="snap.discord.discord" pid=18216 comm="Discord" requested_mask="read" denied_mask="read" peer="unconfined"
[11016.951751] audit: type=1400 audit(1568315092.037:149134): apparmor="DENIED" operation="ptrace" profile="snap.discord.discord" pid=18216 comm="Discord" requested_mask="read" denied_mask="read" peer="unconfined"
[11016.951770] audit: type=1400 audit(1568315092.037:149135): apparmor="DENIED" operation="ptrace" profile="snap.discord.discord" pid=18216 comm="Discord" requested_mask="read" denied_mask="read" peer="unconfined"
[11016.951790] audit: type=1400 audit(1568315092.037:149136): apparmor="DENIED" operation="ptrace" profile="snap.discord.discord" pid=18216 comm="Discord" requested_mask="read" denied_mask="read" peer="unconfined"
```
**解決方法1:** 允許掃proc
```
$ snap connect discord:system-observe
```
**解決方法2:** 不許proc
1. 編輯設定檔`/var/lib/snapd/apparmor/profiles/snap.discord.discord`, 在最後一個`}`之前加入以下指令
```
deny /proc/@{pid}/cmdline r,
deny ptrace (read),
```
2. 重新套用(?)設定檔
```
$ sudo apparmor_parser -r /var/lib/snapd/apparmor/profiles/snap.discord.discord 
```
3. 可能需要重啟discord吧？

>[time=1 Jan 2021] (Happy New Year! 🥳 )


## 新增swapfile

ref: [askubuntu.com](https://askubuntu.com/a/927909), [digitalocean](https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-20-04), [linuxize](https://linuxize.com/post/how-to-add-swap-space-on-ubuntu-18-04/)
(see [askubuntu.com](https://askubuntu.com/a/927870) on how to *increase* current swapfile)

#### Check current available swapfile(s):
<pre><font color="#4E9A06"><b>malleo@malleo-swift</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo swapon --show
NAME      TYPE SIZE USED PRIO
/swapfile file 1.3G   0B   -2
<font color="#4E9A06"><b>malleo@malleo-swift</b></font>:<font color="#3465A4"><b>~</b></font>$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.7Gi       2.9Gi       2.0Gi       697Mi       2.8Gi       3.8Gi
Swap:         1.3Gi          0B       1.3Gi
</pre>
Only one swapfile `/swapfile` in use, total available swap space is 1.3G.

#### Write a new file using `dd`:
Don't use `fallocate` because it makes sparse files. `of=/your/new/swapfile`, `count=1K bs=1M` makes a 1GiB file, increase `count` according to how big you want the swapfile to be.
<pre><font color="#4E9A06"><b>malleo@malleo-swift</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo dd if=/dev/zero of=/swapfile2 count=8K bs=1M
8192+0 records in
8192+0 records out
8589934592 bytes (8.6 GB, 8.0 GiB) copied, 16.8044 s, 511 MB/s
</pre>

#### Set file permissions:
<pre><font color="#4E9A06"><b>malleo@malleo-swift</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo chown root:root /swapfile2
<font color="#4E9A06"><b>malleo@malleo-swift</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo chmod 600 /swapfile2
</pre>

#### Set up swapfile:
<pre><font color="#4E9A06"><b>malleo@malleo-swift</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo mkswap /swapfile2
Setting up swapspace version 1, size = 8 GiB (8589930496 bytes)
no label, UUID=8ab992a1-bfe3-4106-a52a-5a15ede20979
</pre>

#### Enable swap
<pre><font color="#4E9A06"><b>malleo@malleo-swift</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo swapon /swapfile2</pre>

#### Make the swap file persistent
Append the following line to `/etc/fstab` 
```
/swapfile2     swap     swap    defaults     0     0
```

#### Check current available swapfile(s) again:
<pre><font color="#4E9A06"><b>malleo@malleo-swift</b></font>:<font color="#3465A4"><b>~</b></font>$ sudo swapon --show
NAME       TYPE SIZE USED PRIO
/swapfile  file 1.3G 256K   -2
/swapfile2 file   8G   0B   -3
<font color="#4E9A06"><b>malleo@malleo-swift</b></font>:<font color="#3465A4"><b>~</b></font>$ free -h
              total        used        free      shared  buff/cache   available
Mem:          7.7Gi       3.1Gi       174Mi       776Mi       4.4Gi       3.5Gi
Swap:         9.3Gi       2.0Mi       9.3Gi
</pre>
There are now two swapfiles in use, and the total available swap space has increased.

> [time=4th Mar, 18:56]