###### tags: `Coding`
# Linux I
## 常見基本指令
1. pwd : 列印工作路徑
2. mkdir : 建立目錄(folder)
3. ls : 列出工作路徑下的檔案或是目錄清單。
* ls -l :查看權限
4. cd : 切換目錄的路徑
5. rm : 刪除檔案、目錄
6. cp : 拷貝檔案、目錄
7. mv : 移動檔案、目錄
8. touch : 建立一個空的文件檔
9. chmod : 變更檔案權限
* chmod [選項] [模式] [檔案]
* -f, --silent, --quiet:隱藏任何錯誤訊息。
* -v, --verbose:列出每個檔案處理之詳細過程。
* -c, --changes:與-v類似,但是只列出有更改之過程。
* -R, --recursive:以遞迴的方式對目前目錄下的所有檔案及子目錄進行更改。
* --help:列出幫助資訊。
* --version:列出版本資訊。
* ls -l -> 類似-rwxrwxrwx的字串
* 第一個字元為'-':檔案 / 第一個字元為'd':資料夾
* 九個字元三個三個一組,分別代表為:使用者、群組、其他使用者對這個檔案的權限
* 權限有三個字元,分別代表為:
* r(read):讀取的權限
* w(write):修改的權限
* x(execute):執行的權限
* chmod 調控權限(文字方式):
* chmod a+w filename... //讓所有使用者都有編輯filename檔案的權限。當中指令可拆解為如下
* 指定對象:'a' -> 所有使用者 / 'u' -> 檔案擁有者/ 'g' -> 檔案所屬群組的使用者/ o -> 其他使用者
* 運算子:'+' -> 將屬性加到使用者上 / '-' ->將屬性從使用者上移除/ '=' -> 將屬性assign到使用者上
* 屬性: 'r' -> 讀取權限 / 'w' -> 編輯權限 / 'x' -> 執行權限 /'X' -> 若對象為資料夾,或所有使用者裡已有人有執行權限,則給予執行權限/ 'u' -> 檔案擁有者目前所持有之權限 / 'g' -> 檔案所屬群組之使用者目前所持有之權限 /'o' -> 其他使用者目前所持有之權限
* chmod調控權限(數字方式):
* chmod 764 filename...
* r屬性值:4, w屬性值:2, x屬性值:1
* 若希望User擁有rwx屬性,則a值為4+2+1=7
* 若希望Group擁有rw-屬性,則b值為4+2=6
* 若希望Other擁有r--屬性,則c值為4
* chmod 777 * 將當前目錄裡所有檔案之任何權限開放給所有人
10. sudo : 提升權限
* 於/etc/sudoers內可調控哪些使用者有super權限如下:
* 帳號名稱 來源主機=(可切換帳號) 可執行的指令
* accmgr ALL=(root) !/usr/bin/passwd, /usr/bin/passwd [A-Za-z]*, !/usr/bin/passwd root
* 上面式子設定出:accmgr為使用者,只能以root權限執行passwd,然而於設定時加上不能直接執行passwd(避免更改到root),只能使用passwd加上使用者名稱,同時於最後加上硬條件,避免更改到root密碼。
11. poweroff : 關機
12. man : 萬能的男人
* 在指令前加上man,可以找到對應的使用手冊
----
## 環境變數
這邊講一下設定環境變數的幾個做法.
1. export指令
```export PATH="$PATH":/home/bin```
或
```export PATH=${PATH}:/home/bin```
輸入之後可以使用export指令來查看環境變數是否有輸入進去。
*此修改重開機後,就必須再作一次
2. 修改profile
profile的路徑是在 "/etc/profile"
直接修改profile這個檔案在裡面加入
```export PATH="$PATH":/home/bin```
或
```export PATH=${PATH}:/home/bin```
*此修改必須在重開機之後,才會有作用
3. 修改.bashrc
.bashrc的路徑是在"/home/danny/.bashrc"
在檔案最後面加入
```export PATH="$PATH":/home/bin```
或
```export PATH=${PATH}:/home/bin```
*此修改只需關掉Terminal在開啟後,就都會被設定
4. 修改 /etc/enviroment
這檔案裡面包含原本PATH變數的資料, 要增加請在最後面用:加上你要加入的路徑即可
```PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin"```
--------
## Remove Duplicate Text Line
* sort command – Sort lines of text files in Linux and Unix-like systems.
* uniq command– Rport or omit repeated lines on Linux or Unix
### Removing Duplicate Lines With Sort, Uniq and Shell Pipes
```
sort {file-name} | uniq -u
sort file.log | uniq -u
```
### Remove duplicate lines with uniq
建立一檔案如下:
```
cat garbage.txt
```
其內容如下:
```
this is a test
food that are killing you
wings of fire
we hope that the labor spent in creating this software
this is a test
unix ips as well as enjoy our blog
```
利用uniq -u移除重複內容:
```
$ sort garbage.txt | uniq -u
```
output內容如下:
```
food that are killing you
unix ips as well as enjoy our blog
we hope that the labor spent in creating this software
wings of fire
```
<a href="https://www.cyberciti.biz/faq/unix-linux-shell-removing-duplicate-lines/"> more information for remove duplicate line</a>
-----
## apt
### storage
 藉由apt-get install安裝的package,會被除存在:<br>
```
/var/cache/apt/archives
```
----
## R
### 安裝Rscript:<br>
```
apt-get install r-base
```
### 安裝limma:<br>
```
#step 1
$ R #進入R workspace
#step 2
if (!require("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("limma")
```
### 安裝edgeR:<br>
```
#step 1
$ R #進入R workspace
#step 2
if (!require("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("edgeR")
```
### 安裝ggplot2:<br>
```
#step 1
$ R #進入R workspace
#step 2
install.packages("ggplot2")
```
----
## Conda install 問題
1. 遇到:
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: / failed with repodata from current_repodata.json, will retry with next repodata source.
<a href="https://tools-platform-guide.readthedocs.io/zh_CN/latest/anaconda/conda%E5%AE%89%E8%A3%85%E7%8E%AF%E5%A2%83%E6%8A%A5%E9%94%99/">解法</a>
```
# 查询版本
$ conda -V
# 升级
$ conda update -n base conda
# 更新所有版本
$ conda update --all
```