IMOK
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    --- type: slide --- <style> .command { display: inline-block; font-size: 24px; color: black; background-color: white; padding: 7px; border-radius: 10px; margin: 5px; } </style> ## 計算機概論Lab-11 ### LINUX-2 ![image](https://hackmd.io/_uploads/Sk2DN8c7kg.png) <p>https://hackmd.io/@IMOK/Lab11</p> --- <img src="https://hackmd.io/_uploads/ryUSIqnJT.jpg" width=400 style="border-radius:1000px;"/> 講師: 賴昱有 --- ### HOW TO 魔改 TERMINAL ---- ### Bash vs Z Shell <div style="float: left;margin : 0px 0px px 20px"> <img src= "https://hackmd.io/_uploads/HJVmpwc71e.png" width=500 style="margin : 20px 0px 0px 0px"/> </div> <div style="margin : 0px 0px 0px 0px"> <img src= "https://hackmd.io/_uploads/rJom6P97kg.png" width=400 style="margin : 20px 0px 0px 0px"/> </div> ---- + <font size = 5> login shell 改成 zsh</font> + <font size = 5><span class="command">chsh -s /usr/bin/zsh</span></font> + <font size = 5>安裝 oh-my-zsh</font> + <font size = 5><span class="command">sh -c "$(curl -fsSL `https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh`)"</span></font> + <font size = 5>安裝 zsh theme (我用 Powerlevel10k)</font> + <font size = 5><span class="command">git clone --depth=1 `https://github.com/romkatv/powerlevel10k.git` ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k</span></font> ---- + <font size = 5> 編輯 ~/.zshrc 修改 theme</font> + <font size = 5><span class="command">ZSH_THEME="powerlevel10k/powerlevel10k"</span></font> + <font size = 5>重整 shell</font> + <font size = 5><span class="command">exec $SHELL</span></font> + <font size = 5>安裝 zsh-syntax-highlighting</font> + <font size = 5><span class="command">git clone `https://github.com/zsh-users/zsh-syntax-highlighting.git`</span></font> + <font size = 5><span class="command">echo "source ${(q-)PWD}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" >> \${ZDOTDIR:-$HOME}/.zshrc</span></font> + 載入設定檔 + <font size = 5><span class="command">source ~/.zshrc</span></font> ---- ![image](https://hackmd.io/_uploads/HkSslOcmkl.png) --- ### SSH <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> --- ## 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 | --- ### 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 | 修改檔案權限 | | cd | cd directory | 進入資料夾 | | pwd | pwd | 顯示目前的目錄位置 | | echo | echo "hello world" | 輸出文字 | | cat | cat file | 檢視檔案內容 | | less | less 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 | 創建資料夾 | | rmdir | rmdir directory | 刪除空目錄 | | touch | touch file | 創建檔案 | | rm | rm file | 刪除檔案 | ---- <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 機器上修改密碼 | | ls | ls -l | 列出當前目錄下的檔案 | | ll | ll | ls -l的縮寫 | ---- | command | usage | description | | ------- | -------------------- | ------------------ | | vim | vim file | 使用 vim 編輯檔案 | | df | df -h | 列出磁碟剩餘空間 | | du | du –max-depth 1 -h . | 列出資料夾所占空間 | | free | free -h | 列出記憶體使用狀況 | | who | who | 查看目前登入使用者 | | gcc | gcc main.c | 編譯 c 語言檔案 | | g++ | g++ main.cpp | 編譯 c++ 語言檔案 | ---- | command | description | | ------- | ------------------ | | gcc file.c | 編譯 file.c,生成默認執行檔 a.out | | gcc -o output file.c | 編譯 file.c,輸出執行檔為 output | | gcc -c file.c | 只編譯生成目標檔案 file.o 不連結| | gcc -E file.c -o file.i | 只進行預處理,輸出為 file.i | | gcc -S file.c | 只產生組合語言檔案 file.s | | gcc -v file.c | 顯示詳細編譯過程 | ---- <img src= "https://hackmd.io/_uploads/HJAT8nqXJg.png" width=400 style="margin : 0px 0px 0px 0px"/> --- #### DF <font size = 5 >列出磁碟剩餘空間</font> <font size = 5 >e.g.<span class="command">df -h</span></font> #### DU <font size = 5 >列出資料夾所占空間</font> <font size = 5 >e.g.<span class="command"> du --max-depth 1 -h .</span></font> #### FREE <font size = 5 >列出記憶體使用狀況</font> <font size = 5 >e.g. <span class="command">free -h</span></font> ---- #### GCC <font size = 5 >編譯 c 語言檔案</font> <font size = 5 >e.g. <span class="command">gcc main.c</span></font> #### G++ <font size = 5 >編譯 c++ 語言檔案</font> <font size = 5 >e.g. <span class="command">g++ main.cpp</span></font> --- #### PROCESSES AND JOBS ---- <font size = 5 >在指令後面加上<span class="command"> & </span>可以放到背景執行</font> <font size = 5 >e.g. <span class="command">sleep 60 &</span></font> <font size = 5 >用<span class="command"> ps </span>列出當前所有 process</font> <font size = 5 >用<span class="command"> jobs </span>可以看到正在背景執行的 process</font> <img src= "https://hackmd.io/_uploads/SJxvL_q71e.png" width=400 style="margin : 0px 0px 0px 0px"/> ---- <font size = 5 >執行程式時可以用組合鍵<span class="command"> Ctrl+c </span>傳送停止訊號</font> <font size = 5 >或是用<span class="command"> Ctrl+z </span>將程式暫停後放到背景</font> <font size = 5 >放到背景後可以用<span class="command"> fg %1 </span>把它放到前景繼續執行</font> <font size = 5 >或是<span class="command"> bg %1 </span>讓他在背景繼續執行</font> <img src= "https://hackmd.io/_uploads/ryMUOdqmJx.png" width=700 style="margin : 20px 0px 0px 0px"/> ---- <font size = 5 >可以使用<span class="command"> kill %1 </span>對程式發送訊號</font> <font size = 5 ><span class="command">kill </span>並不是只能發送停止訊號</font> <img src= "https://hackmd.io/_uploads/ryPaO_qXkl.png" width=500 style="margin : 20px 0px 0px 0px"/> --- ### REDIRECTION <font size = 5 >overwrite:<span class="command">echo "string" > file.txt</span></font> <font size = 5 >append:<span class="command">echo "string2" >> file.txt</span></font> --- ### PIPE <font size = 5 ><span class="command">cat file.txt | grep "apple"</span></font> <font size = 5 ><span class="command">cat /proc/meminfo | grep Pages | sort</span></font> <font size = 5 ><span class="command">du -d 1 -h | sort -h</span></font> <img src= "https://hackmd.io/_uploads/Hy-Dt_cX1g.png" width=400 style="margin : 0px 0px 0px 0px"/> --- ### WILDCARDS <font size = 5 ><span class="command">ls *.txt</span></font> <font size = 5 ><span class="command">cat file *</span></font> --- ### ARCHIVING [GNU / Linux 各種壓縮與解壓縮指令 - 凍仁的筆記](https://note.drx.tw/2008/04/command.html) + <font size = 5 >打包</font> + <font size = 5 ><span class="command">tar cvf FileName.tar DirName</span></font> + <font size = 5 >解包</font> + <font size = 5 ><span class="command">tar xvf FileName.tar</span></font> + <font size = 5 >打包且壓縮</font> + <font size = 5 ><span class="command">tar zcvf FileName.tar.gz DirName</span></font> + <font size = 5 >解包</font> + <font size = 5 ><span class="command">tar zxvf FileName.tar.gz</span></font> --- ## 作業網站 作業做完請上傳到 http://140.121.197.13/tutorial 並且注意上傳時間限制、檔名、其他規範 上課時提前做完可以直接給助教 demo 登記 就不需要上傳 demo 過的部分 ---- ## Question 1 <font size=6> Count the disk usage of your <span class="command">www</span>directory. </font> ---- ## Question 2 <font size=6>Write a program to find the prime numbers between 1 and 10000 and compile it using gcc or g++. </font> ---- ## Question 3 <font size=6>Execute the file and redirect the output to the file <span class="command">primes.txt</span>. </font> ---- ## Question 4 <font size=6>[Insertion sort intro](https://www.youtube.com/watch?v=JU767SDMDvA)</font> <font size=5>Allow the user to input 10 numbers, then sort them using the insertion sort and save the sorted result to a file <span class="command">isort10.txt</span>. </font> ---- ## Question 5 <font size=5>Complete the 99 multiplication table using only one loop and output the result to a file named <span class="command">1loop99.txt</span>. ![image](https://hackmd.io/_uploads/SkTMa39XJl.png) </font>

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully