尼的小知識

下載python

  1. 官網下載python(可以看一下自己要下載的版本)
    Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →
  2. 執行他
  3. 如果有add to path的選項就打勾他
  4. 讓他下載
  5. 打開cmd看看他可不可以正常執行

VScode-Visual Studio Code

IDE

IDE的英文全名是Integrated Development Environment,中文譯為:整合開發環境。
以前的程式開發撰寫,如撰寫程式碼需要一套類似文書處理器的軟體,我們稱編輯器(Editor);程式寫好後需要編譯,就再需要一個編譯器(Compiler);寫完的程式可能有一部分要跟其他程式連結在一起,又需要一個連結器(Linker),在同一個程式操作畫面中,既可以編輯程式碼文字,也可以編譯、連結、除錯等,因為把原本各自散落的程式開發工具統整在一起。

  • 簡稱VS Code,是一款由微軟開發且跨平台的免費原始碼編輯器
  • Visual Studio Code下載連結
  • 此畫面選項全勾,其餘皆使用預設值安裝
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

Terminal 是甚麼

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

相信許多人在學習程式設計到一個階段之後,總會去面臨到要使用 Linux 系統的機會。而使用 Linux 系統最重要的技能就是懂得使用終端機(terminal)來進行各種操作。

然而撇去看到一堆黑底白字看起來很可怕的畫面之外,terminal 令人害怕的其中一個點是會看到一堆奇怪的語法而不懂得那是什麼意思,還有可能因為下錯指令而對電腦造成難以逆轉的後果。

為了讓大家稍微比較了解 terminal 究竟怎麼使用,今天就來跟大家簡介一下所謂的 terminal,或者更精確的說是 Linux 系統中的命令列介面(command-line interface,CLI)

Why terminal?

實際上,所謂的終端機 terminal,正確來說是一種文字使用者介面,望文生義可知就是「使用文字和使用者互動的介面」。想像一下當我們今天要和一個人溝通時,最主要的方式就是使用語言向對方傳遞訊息,而今天如果將這種語言的對象變成機器,來對電腦進行溝通,就是文字使用者介面,簡言之就是對著電腦說話的意思。而由於對機器說的「話」通常都是一個又一個的「命令」因此通常稱之為「命令列介面」,常常也會被叫做 command-line 或 CLI。與之相對的則是圖形使用者介面(graphical user interface,GUI),也就是平常各位用滑鼠操作的、可以點擊並看到畫面的使用者介面。

而在電腦的作業系統中,為了讓電腦「聽得懂我們要它做什麼」,就需要一種語言來向電腦下指令。在 Linux (與 MacOS)系統中,命令列介面叫做「Unix shell」,而其構成的語言則常稱為「shell language」或 「shell script」。

ssh 鑰匙/給樹莓派

  1. 先去 ~/.ssh 看看是否有鑰匙
  2. ssh-keygen
    命令預設會在 ~/.ssh 目錄中產生 4096 位 SSH RSA 公用和私鑰檔案。 如果在目前位置找到現有的 SSH 金鑰組,則會覆寫這些檔案。
  3. 會生成 ~/.ssh/idrsa, ~/.ssh/idrsa.pub
    • ~/.ssh/idrsa 為私鑰,不可以給別人喔
    • ~/.ssh/idrsa.pub 為公鑰,放在要連線的設備
  4. 在 樹梅派新增 (若沒有的話) ~/.ssh/authorized_keys
  5. 將公鑰貼在裡面

樹莓派設置 其他 wifi

這部分發現容易失敗,先連結原本的電腦熱點,之後再更新作法

  1. 連線到 樹梅派 之後輸入 sudo raspi-config
  2. 進入 system options
  3. 選擇 Wireless LAN
  4. 輸入 WIFI 帳號密碼
  5. 稍等一下便可以連線成功

vpn 連線/內網

終端指令

會用到的東西!

  • help
    • 查看指令說明
  • google
    • 你遇到的問題,一定有其他人遇過
  • tab
    • 列出可使用的指令 或補全指令
  • ctrl-C
    • keyboard interrupt
  • 向上方向鍵:上一個指令

路徑

  • 絕對路徑:路徑的寫法『一定由根目錄 / 寫起』,例如: /usr/share/doc 這個目錄。
  • 相對路徑:路徑的寫法『不是由 / 寫起』,意指『相對於目前工作目錄的路徑!』
    例如由 /usr/share/doc 要到 /usr/share/man 底下時,可以寫成: 『cd ../man
  • 目前資料夾
  • ../ 上一層資料夾
  • ~/ 家目錄
  • / 根目錄
  • Image Not Showing Possible Reasons
    • The image was uploaded to a note which you don't have access to
    • The note which the image was originally uploaded to has been deleted
    Learn More →

常用終端機命令列指令

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

cd

切換目錄

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

cd demo (進入名為demo的資料夾)
cd .. (返回至上一層資料夾)
cd (返回家目錄)

ls (LS 不是 is)

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

取得當前資料夾與檔案名稱

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

-l 詳細資料
-a 顯示隱藏檔案
Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

ls -la (以詳細資料格式列出當前資料夾與檔案名稱,並顯示隱藏檔案)

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

在windows用dir
dir /a 顯示隱藏檔案

mkdir

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

make directory
建立資料夾

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

mkdir demo (建立一個名為demo的資料夾)
  • 禁用字元:/、空白
  • 建議使用數字、符號、_(底線)

touch

用來建立檔案
touch test.txt
在windows會用
cd > test.txt

rm

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

刪除檔案

rm text2 (刪除叫做text2的檔案)

-r 刪除資料夾(-r代表他會用遞迴的方式處理資料夾中的資料)

rm -r demo (刪除叫做demo的資料夾)

在windows用del

mv

移動檔案或資料夾/更改檔案或資料夾名稱


也可以用來改名

mv text text2 (將text名稱改為text2)

在windows用move

cp

複製檔案
-r 複製資料夾

cp text2 text (複製text2檔案 並命名為text)

在windows用copy

clear

清除終端的裡面的訊息,看起來比較乾淨
在windows裡面是cls

Git

Git 已成為版本控制的全球標準

Git 是分散式版本控制系統,這表示專案的本機複本是完整的版本控制存放庫。 這些功能完整的本機存放庫可讓您輕鬆地離線或遠端工作。 開發人員在本機認可其工作,然後同步處理其存放庫複本與伺服器上的複本。 此種模式與集中式版本控制不同。集中式版本控制的用戶端必須與伺服器同步程式碼,之後才能建立新版本的程式碼。

有 Git 幫你保留這些歷史紀錄跟證據,萬一出事的時候你就能知道是從什麼時候開始就有問題,以及知道該找誰負責。

git的優點:

  1. 免費、開源
  2. 速度快、檔案體積小
  3. 分散式系統

git的優點
Git 的指令有非常多,而且有的指令有點複雜,但是主要把基礎指令學會就好了!

下載git

  1. 進去官網
  2. 點選右邊的下載
  3. 打開終端輸入git --version確認下載成功

git config設定

git config --global user.name "你的姓名"
git config --global user.email "您的Email"

在 Git 每次的檔案版本發佈時,都會記錄該版本是哪位開發者做的。

ssh 連線設定

SSH 的出現就是為了解決這樣子的情況。安全是 SSH 的賣點。SSH 它讓我們在與遠端電腦(遠端伺服器)連線時,能夠先將訊息加密過後再傳送,並且確保只有「被認可的人」才能夠解密訊息。因此,就算是在一個不安全的網絡裡面,SSH 都能夠確保連線不被竊聽。

只要提到木馬病毒的鍵盤記錄器會將鍵盤上所輸入的字母皆側錄下來,又或者在免費的公開網路有被側錄封包的風險,以安全性的角度來看,使用金鑰登入 SSH 的方式相對安全許多,前提是金鑰檔案要保管好,不能外流。

將git連上github

github只允許使用公鑰登入,不允許輸入密碼的方式

  1. 輸入ssh-keygen打一把要鑰匙,預設為 /home/username/.ssh/id_rsa
  2. 接下來會問你鑰匙存放的位置還有 pass phrase會有三個問題,可以都直接用預設即可。(按enter就好)
  3. 輸入cat ~/.ssh/id_rsa.pub會顯示公鑰資料,把它複製下來

    這邊cat指令只能用在Macos/Linux,再windows要用vscode開啟.ssh資料夾再點選id_rsa.pub,複製裡面的東西
  4. 我們回到github點到setting

    點選 SSH and GPG keys

    點選 new SSH key
  5. 將複製貼上到key欄位 輸入title(不能用中文!!) 按add SSH key
  6. 確認是否連到線輸入ssh -T git@github.com,他可能會確定連線,這時候打yes,出現
    The authenticity of host 'github.com (IP ADDRESS)' can't be established.就是有連線到了

簡單使用流程

  1. git clone將你在github的資料下載回來

    輸入指令git clone "剛剛的複製"他就會下載到指定資料夾。
  2. 可以用ls 看看有沒有新增到
  3. cd 進剛剛clone進來的資料夾,輸入git status察看她現在的狀態
  4. 進行變更
  5. git add --all將所有檔案加入暫存區
  6. git commit -m "first commit" (first commit為這一次上傳的名稱 不可重複)
  7. git push將檔案上傳到雲端資料庫

查看歷程

git log 查看commit歷程 會有完整資訊

可以使用git log --oneline查看commit歷程
oneline他只顯示commit訊息以及commit id,以一行的方式精簡地顯示出commit歷史

使用git pull讓現在的本地repo更新到遠端repo的進度

退回進度

使用git reset --hard HEAD~1
退回之前提交的版本
若要回到前N次的提交版本
git reset --hard HEAD~N