<style>
.command {
display: inline-block;
font-size: 24px;
color: black;
background-color: white;
padding: 7px;
border-radius: 10px;
margin: 5px;
}
</style>
## 計算機概論Lab-10
### LINUX

<p>https://hackmd.io/@IMOK/Lab10</p>
---
<img src="https://hackmd.io/_uploads/ryUSIqnJT.jpg" width=400 style="border-radius:1000px;"/>
講師: 賴昱有
---
<img src="https://hackmd.io/_uploads/BJqae3xX1e.png" width=400 />
---
### OS
<style>
ul {
padding-left: 35px; /* 調整縮排 */
}
li {
font-size: 30px; /* 調整標點大小 */
}
</style>
<ul>
<li>Windows</li>
<li>Unix
<ul>
<li>Unix-like
<ul>
<li>BSD
<ul>
<li>FreeBSD</li>
<li>Darwin
<ul>
<li>MacOS</li>
<li>iOS</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>Linux
<ul>
<li>Ubuntu</li>
<li>Arch</li>
<li>Android</li>
</ul>
</li>
</ul>
---
### UNIX
<font size = 5>20 世紀 70 年代由 AT&T 的貝爾實驗室開發多使用者、多任務的作業系統</font>
<br>
### UNIX LIKE
<font size = 5>模仿了 Unix 的設計與概念的衍生系統其中 BSD 系列與 MacOS 較為知名</font>
---
### GNU
<font size = 5> GNU's Not Unix!</font>
<font size = 5>推動自由、開源軟體的組織</font>
<font size = 5>最初的目標是建立一個完整的作業系統替代Unix</font>
<font size = 5>其提供工具包含GCC、Bash、glibc等</font>
<font size = 5>原使用GNU Hurd後使用Linux kernel作為核心</font>
<font size = 5>如 Debian、Ubuntu、Red Hat皆為GNU/Linux系統</font>
---
### Terminal
<font size = 5>Terminal or Console為用戶與主機進行互動的硬體裝置 </font>
<font size = 5>如今多數情況下,通常指的是 CMD(命令提示字元)等虛擬介面。</font>
----
### Shell
<font size = 4>使用者與作業系統之間的接口</font>
<font size = 4>將使用者指令解析後,與作業系統內核(Kernel)進行溝通</font>

----
### 常見的Shell種類
+ <font size = 4>Bourne Shell(sh):最早期的 SHELL,由 UNIX 開發。</font>
+ <font size = 4>Bash(Bourne Again Shell):基於 Bourne Shell,加入許多新功能。</font>
+ <font size = 4>C Shell(csh):以 C 語言語法為基礎,適合熟悉 C 語言的使用者。</font>
+ <font size = 4>Korn Shell(ksh):結合 Bourne Shell 和 C Shell 的優點,適用於高效能腳本需求。</font>
+ <font size = 4>Z Shell(zsh):功能非常強大,兼容 Bash,但在腳本撰寫、介面美化及插件支援方面表現更佳。</font>
+ <font size = 4>Windows powershell : 內建於Windows系統,僅限於 Windows 作業系統使用。</font>
---
### ssh(secure shell)
<font size = 5>是一種遠端連線的協定</font>
<font size = 5>不過是文字介面的</font>
<font size = 5>使用非對稱式加密 相比 telnet 更安全</font>
<font size = 5>用法 : <span class="command">ssh {user}@{host}</span></font>
<font size = 5>e.g. <span class="command">ssh b0135XXXX@linux.aclab.cool</span></font>
<font size = 5>or 使用 GUI (Bitvise SSh Client)</font>
----
### SFTP (Secure File Transfer Protocol)
<font size = 5>基於 SSH 的檔案傳輸協議,提供類似於 FTP 的功能,但所有通信都經過加密。
提供了文件操作的完整功能,如檔案上傳、下載、刪除、檔案權限修改等。)</font>
### SCP (Secure Copy Protocol)
<font size = 5>基於 SSH 的檔案傳輸工具,用於快速、安全地傳輸檔案。
它的功能比 SFTP 簡單,主要專注於檔案的上傳和下載。)</font>
---
### 檔案系統結構
<div style="float: left;margin : 0px 0px px 20px">
<img src= "https://hackmd.io/_uploads/S1KM36xmJl.png" width=650 style="margin : 20px 0px 0px 0px"/>
</div>
<div style="margin : 0px 0px 0px 0px">
<img src= "https://hackmd.io/_uploads/S12x3plQJx.png" width=300 style="margin : 20px 0px 0px 0px"/>
</div>
---
### 檔案權限
<font size = 5 > 列出檔案 <span class="command">ls -l</span></font>

<font size = 5 ><span class="command">- rwx r- - r- -</span></font>
<style>
table {
width: 50%;
border-collapse: collapse;
line-height: 1; /* 行距 */
}
th, td {
font-size: 24px; /* 字體大小 */
}
</style>
| permission |count | description |
| ----------- | ---------------------------------- | ----- |
| r | 4 | 讀取 |
| w | 2 | 輸入 |
| x | 1 | 執行 |
----
<style>
table {
width: 60%;
border-collapse: collapse;
line-height: 1.5; /* 行距 */
}
th, td {
font-size: 28px; /* 字體大小 */
}
</style>
| permission |count | description |
| ----------- | ---------------------------------- | ----- |
| r | 4 | 讀取 |
| w | 2 | 輸入 |
| x | 1 | 執行 |
| permission |add up |
| ----------- | ---------------------------------- |
| r w x| 4+2+1=7 |
| r w - | 4+2=6 |
| r - x | 4+1=5 |
|- - x|1|
----
<font size = 5 ><span class="command">chmod 666 example.txt</span></font>

---
### COMMANDS
<font size = 5 >如果不知道指令怎麼用 請參考</font>
<font size = 5 ><span class="command">command --help</span></font>
<font size = 5 ><span class="command">man command</span></font>
---
### Quick search table
----
<style>
table {
width: 80%;
border-collapse: collapse;
line-height: 1.5; /* 行距 */
}
th, td {
font-size: 28px; /* 字體大小 */
}
</style>
| command | usage | description |
| ------- | ----- | ----------- |
| chsh | chsh /bin/tcsh | 修改預設登入 shell |
| passwd | passwd | 修改密碼 |
| chmod | chmod 664 file | 修改檔案權限 |
| ls | ls -l | 列出當前目錄下的檔案 |
| cd | cd directory | 進入資料夾 |
| pwd | pwd | 顯示目前的目錄位置 |
| echo |echo "hello world" | 輸出文字 |
| cat | cat file | 檢視檔案內容 |
----
<style>
table {
width: 80%;
border-collapse: collapse;
line-height: 1.5; /* 行距 */
}
th, td {
font-size: 28px; /* 字體大小 */
}
</style>
| command | usage | description |
| ------- | --------------- | ---------------- |
| head | head -n 10 file | 檢視檔案前10行 |
| tail | tail -n 10 file | 檢視檔案最後10行 |
| grep | grep "apple" example.txt | 擷取有關鍵字的那一行 |
| cp | cp file file_copy | 複製檔案 |
| mv | mv file file_moved | 移動、重新命名檔案 |
| mkdir | mkdir directory | 創建資料夾 |
| touch | touch file | 創建檔案 |
| vim | vim file | 使用 vim 編輯檔案 |
----
<style>
table {
width: 80%;
border-collapse: collapse;
line-height: 1.5; /* 行距 */
}
th, td {
font-size: 28px; /* 字體大小 */
}
</style>
| command | usage | description |
| -------- | ------------------------ | -------------------- |
| chsh |chsh /bin/tcsh | 修改預設登入 shell |
| ypchsh | ypchsh /bin/tcsh | 在 NIS 機器上修改預設登入 shell |
| passwd | passwd | 修改密碼 |
| yppasswd | yppasswd | 在 NIS 機器上修改密碼 |
---
#### CHSH (YPCHSH)
<font size = 5 >修改預設登入 shell</font>
<font size = 5 >e.g.<span class="command">chsh /bin/tcsh</span></font>
#### PASSWD (YPPASSWD)
<font size = 5 >修改密碼</font>
<font size = 5 >e.g.<span class="command"> passwd</span></font>
#### CHMOD
<font size = 5 >修改檔案權限</font>
<font size = 5 >e.g. <span class="command">chmod 777 file</span></font>
----
#### LS
<font size = 5 >列出目錄中的檔案與目錄列表</font>
<font size = 5 >常用參數 <span class="command">-l -h -a</span></font>
<font size = 5 >e.g. <span class="command">ls -alh</span></font>
#### CD
<font size = 5 >進入資料夾</font>
<font size = 5 >e.g. <span class="command">cd Documents</span></font>
#### PWD
<font size = 5 >顯示目前的目錄位置</font>
----
#### ECHO
<font size = 5 >輸出文字</font>
<font size = 5 >e.g. <span class="command">echo "Hello World!!!"</span></font>
<font size = 5 >輸入檔案用法:</font>
<font size = 5 >e.g. <span class="command">echo "Hello World!!!" > file</span></font>
#### CAT
<font size = 5 >~~叫貓貓去看一下檔案~~</font>
<font size = 5 >檢視檔案內容</font>
<font size = 5 >e.g. <span class="command">cat file</span></font>
----
#### HEAD
<font size = 5 >檢視檔案前x行</font>
<font size = 5 >常用參數 <span class="command">-n</span></font>
<font size = 5 >e.g. <span class="command">head -n 10 file</span></font>
#### TAIL
<font size = 5 >檢視檔案最後x行</font>
<font size = 5 >常用參數 <span class="command">-n</span></font>
<font size = 5 >e.g. <span class="command">tail -n 10 file</span></font>
----
#### GREP
<font size = 5 ><span class="command">g/re/p</span>(globally search a regular expression and print)</font>
<font size = 5 >e.g.<span class="command"> grep "apple" example.txt</span></font>
<img src= "https://hackmd.io/_uploads/ByFmACg7kg.png" width=300 style="margin : 0px 0px 0px 0px"/>
<font size = 5 ><span class="command">grep -i "apple" example.txt for case-insensitive</span></font>
----
#### CP
<font size = 5 >複製</font>
<font size = 5 >e.g.<span class="command"> cp hello hello-copy</span></font>
#### MV
<font size = 5 >移動、更名</font>
<font size = 5 >e.g. <span class="command">mv hello ../hello</span></font>
#### MKDIR
<font size = 5 >創建資料夾</font>
<font size = 5 >e.g.<span class="command"> mkdir my-dir</span></font>
---
## VIM
<font size = 6 >文字介面編輯器</font>
----
<div style="text-align: center;">
<font size =7 style="margin : 0px 0px 0px 40px">分成三種模式</font>
<br>
<br>
<ul>
<li>normal mode</li>
<li>edit mode</li>
<li>visual mode</li>
</ul>
</div>
<br>
<font size = 6 >一開始是 normal mode 按 <span class="command">i</span> 進入 edit mode</font>
<font size = 6 >按 <span class="command">ESC</span> 回到 normal mode</font>
----
<font size = 6 >在 normal mode 打冒號可以輸入指令</font>
<style>
table {
width: 80%;
border-collapse: collapse;
line-height: 1.5; /* 行距 */
}
th, td {
font-size: 28px; /* 字體大小 */
}
</style>
| Command | Description |
| ------- | ----------- |
| :w | 儲存 |
| :wq | 儲存並退出 |
| :q! |不儲存退出 |
----
<font size = 5 >vim 是個很強大的編輯器</font>
<font size = 5 >在 normal mode 可以用的指令還有連技超多</font>
<font size = 5 >如果想了解的可以看看 這個[Vim](https://mropengate.blogspot.com/2015/07/vim-ch2.html)</font>
<font size = 5 >推薦要學 只能用文字介面的時候非常好用</font>
---
### JOE
<font size = 5 >另一個文字介面編輯器</font>
<font size = 5 ><span class="command">joe filename.txt</span></font>
<style>
table {
width: 80%;
border-collapse: collapse;
line-height: 1.5; /* 行距 */
}
th, td {
font-size: 28px; /* 字體大小 */
}
</style>
| operation | description |
| --------- | ---------------- |
| Ctrl+K,H | show help |
| Ctrl+K,F | search text |
| Ctrl+K,L | go to line |
| Ctrl+K,S | save file |
| Ctrl+K,X | save file and exit editor |
| Ctrl+Y| delete a line |
---
## 作業網站
作業做完請上傳到 http://140.121.197.13/tutorial
並且注意上傳時間限制、檔名、其他規範
上課時提前做完可以直接給助教 demo 登記
就不需要上傳 demo 過的部分
----
## Question 1
<font size=6>
Create a directory named <span class="command">www</span>.
</font>
----
## Question 2
<font size=6>Change the permission of the directory <span class="command">www</span> to <span class="command">drwxr-xr-x</span>, and explain what does this mean.
</font>
----
## Question 3
<font size=6>From the previous exercises, upload your personal web page to the www directory. Use http://linux.aclab.cool/~b0135XXXX/ to view the page.
</font>
----
## Question 4
<font size=6>Copy the file <span class="command">/proc/cpuinfo</span> to your directory, and rename the file to <span class="command">CPU</span> (case sensitive).</font>
----
## Question 5
<font size=6>Dump (show) the content of the file CPU and isolate
(using Linux commands) the CPU model.</font>
<img src= "https://hackmd.io/_uploads/H1dH2kWQJg.png" width=500 style="margin : 0px 0px 0px 0px"/>
{"title":" 計算機概論Lab-10","description":"image","contributors":"[{\"id\":\"738dd674-cd6a-462c-87e2-b67e68f12ac0\",\"add\":16014,\"del\":4331}]"}