以下紀錄Ubuntu常見的問題
眾多Q&A
以下問題,打從安裝Ubuntu系統就會慢慢遇到。
很多問題只能不斷補上,真的是無止盡的debug
有些遇過好幾次,有些則是新問題
#環境篇
系統環境設定相關的部份
// .local資料夾的用途
.local的存在,其實在早期的Ubuntu比較沒有看過
這是因為有一個致力於open file system的組織
希望能在Linux平台上,有統一的目錄結構
而不是散散亂亂每個發行版都不太一樣
.local是這樣誕生的,其他還有.config現在也是蠻常見的
可以收納家目錄下各種檔案
所以這個問題可以參考
whats-the-local-folder-for-in-my-home-directory
// Hard Link & Soft Link
簡單講…
使用者看到的檔案與系統內部的Inode是一個連結關係
如果把原檔案刪除(非檔案的Inode)
在hard link下連結仍可以存取Inode,但在soft link下就沒辦法…
也就是soft link更像字面上講的的link
詳細參照Reference
// 解除dash為Ubuntu default console
網路上很多亂搞的指令,還直接強制替換連結勒
看來看去,這個比較是正解
sudo dpkg-reconfigure dash
// 還原預設.bashrc
亂搞.bashrc導致一些意外狀況發生時
Ubuntu在/etc/skel/下,有個預設的bashrc可以還原
// 修改 console ‘$’ 前的顯示資訊
Ubuntu 預設的路徑進到比較深層的資料夾後
路徑會拖很長,可能打命令打到一半就換行了
修改 $PS1 變數可以解決這個情況
$PS1可以顯示的變數如下:
\d - the date in "Weekday Month Date" format (e.g., "Tue May 26")
\e - an ASCII escape character (033)
\h - the hostname up to the first .
\H - the full hostname
\j - the number of jobs currently run in background
\l - the basename of the shells terminal device name
\n - newline
\r - carriage return
\s - the name of the shell, the basename of $0 (the portion following the final slash)
\t - the current time in 24-hour HH:MM:SS format
\T - the current time in 12-hour HH:MM:SS format
\@ - the current time in 12-hour am/pm format
\A - the current time in 24-hour HH:MM format
\u - the username of the current user
\v - the version of bash (e.g., 4.00)
\V - the release of bash, version + patch level (e.g., 4.00.0)
\w - Complete path of current working directory
\W - the basename of the current working directory
\! - the history number of this command
\# - the command number of this command
\$ - if the effective UID is 0, a #, otherwise a $
\nnn - the character corresponding to the octal number nnn
\\ - a backslash
\[ - begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt
\] - end a sequence of non-printing characters
參考Reference (剛好遇到這個問題)
# 操作篇
比較與操作有關的問題
// tmux 下面點擊ctrl + s,讓畫面freeze該如何解除
ctrl + q,解除freeze
// 讓ls按照資料夾, 隱藏檔, 檔案, 再按字母排
個人覺得預設的ls實在太糟糕
資料夾和檔案,以及隱藏檔都混在一起顯示
找東西的時候實在不好找
$ alias ls='ls -v --group-directories-first -N'
// 頁面的移動有兩種
- 一種是操作cursor上下移動,視野被動跟的上下移動,就是一般編輯器的操作
- 一種是操作視野上下移動,cursor不見得會上下移動,稱為scrolling
scrolling用於瀏覽,cursor上下多用於編輯
// 如何在shell script中停止wildcard自動展開
foo '*'
foo *
set -f; foo *; # or disable the glob (noglob)
set -o/+o, set -f/+f
意思相同- 若script是command本身,可用alias完成
alias foo='set -f;foo';foo(){ command foo "$@";set +f;}
# 這行其實不一定要擠在一行
// Shell script的redirect怎麼看
簡單講…
- 目標:1表示stdout, 2表示stderr, &表示兩者
- 動作:<表示stdin, > 表示stdout,-表示關閉符號
- 常用格式:
- M>檔名
- M>&數字,數字表示管道
// 用cmd想反查packagename
用apt-cache
$ apt-cache showpkg foo #顯示foo的package資訊
詳見 Reference
// 新增使用者到group裡面
可避免直接修改目標的使用者權限
有些網路的解答很喜歡直接改目錄權限
例如下面的情況,避免直接修改權限
用到adduser, /etc/group的查詢
$ ls -al
/dev/kvm crw-rw---- 1 root kvm 10, 232 11月 11 20:29 /dev/kvm
$ # 可看出使用者是root, 群組屬於kvm
$ grep kvm /etc/group # 檢查使用者群組中有誰 kvm:x:128:
$ sudo adduser $USER kvm # 加入使用者到群組中
$ grep kvm /etc/group
kvm:x:128:karl
詳見Reference (正好遇到這個問題)
// 重新登入shell而不用重新開機
su - $USER
// 慢慢更新
fasd clang, llvm bison, flex