# 第一章 shell ## Idunit https://rb.gy/nnbdkl --- ## before we start ---- - workshop 需要的工具 - 筆電 ---- - workshop 會用到的線上工具 hackmd https://hackmd.io/hhwVLHk6SA-u8BxFbkqoPQ discord https://discord.gg/UdtEyq slido https://app.sli.do/event/pr46kr0u ---- - 現場資源 - wifi - 電源 ---- - 如果太累 可以睡覺,但請不要打乎吵到其他人。 ---- - 如果覺得講太快 請告訴我 ---- - 由於我們時間有限,我們無法涵蓋所有內容 ---- - 而是挑選幾個代表性的工具跟用法 ---- - 如果覺得內容有誤 - 或覺得講得可以更好 歡迎來意見回饋 bootcamp 工作人員 ---- - Greeting I am jeffery - icafe - self-study to open source with security habbit - teapook - London linux scholarship - consult ---- - 這是第一場的 shell workshop ---- - 今天將涵蓋 - why shell? how shell? - package management concept - shell scripting - own and costumize your shell ---- - 接下來是 - OS - internet - git --- ## Why shell, and how shell? ---- ### 來看個生態報告 - [stackoverflow tech 2020 survey]( https://insights.stackoverflow.com/survey/2020#most-popular-technologies) ---- - Shell? why not start from js,py,c or ...? 明明有那麼多其他技術選擇,為什麼要從 shell 開始? ---- - 幹嘛不直接從 javascript python 還有 c 開始 ---- - Locate needed skill on map - 我們先來看看現代工程師的完整技能樹 ---- - [backend skill roadmap](https://roadmap.sh/backend) ---- - [frontend skill roadmap](https://roadmap.sh/frontend) - 誒,前端沒有需要 shell ,輕鬆,那我選這個! ---- - 那你遲早有一天會需要 devops ---- - 那什麼?很 op 嗎? ---- - dev humors - ![](https://devhumor.com/content/uploads/images/August2020/devops.jpg) ---- - [devops skill roadmap](https://roadmap.sh/devops) ---- - 學校教了那麼多 cs 的領域 - 電腦科學理論 - 科學運算 - 作業系統開發 - 甚至人工智慧 ---- - 卻唯有一個領域被漏掉了 ---- - 學會善用強大的現代開發工具 ---- - 明明是每天在用,好幾千個小時在使用的東西 ---- - 卻放生學生,自學去 ---- - 渴求自動化的我們 ---- - 卻常常忘記電腦是用來自動化人力工作的 ---- - 因為我們卻常常因為缺乏某些關鍵知識 ---- - 仍浪費許多人力處理很多重複的雜務 ---- - 或是沒完全發揮某些強大工具的能力 - 像是 shell IDE vim shell ---- - 最後就會需要仰賴 devops 工程師 ---- - 因此 devops 成為 devloper 中最有價值人才 ---- - 先 QA 想一想、存個紀錄、然後開始動手玩 - slido https://app.sli.do/event/pr46kr0u - hackmd --- # Why shell? ---- - 不能點點圖形介面就好嗎? ---- - 現代的電腦軟體大部分都有著方便的使用介面 ---- - 從圖形介面、聲音辨識甚至AR/VR ---- - 對於 80% 使用場景都沒問題 ---- - 但是這些軟體卻有著最根本的限制 ---- - 你沒辦法按下不存在的按鈕 ---- - 你沒辦法使用還沒被編寫設計的功能 ---- - 為了得到新功能、我們就需要老方法 文字介面 ---- - 幾乎你所有想得到的電子裝置上都有 shell 介面 ---- - 他們功能跟規格大多類似 - 執行程式 - 輸入 - 查看輸出 ---- - Bourne Again Shell,bash - 那個黑黑的介面 ---- - 如何打開它? --- ### How to basic : bash ---- - prompt `user:~$` ---- - date ---- - echo hello ---- - which echo ---- - 用 / 分開,一層層的路徑 ---- - root directory 最上層的路徑 ---- - echo $PATH ---- - cd ---- - path ---- - cd . ---- - cd \.\. ---- - cd ~ ---- - cd \- ---- - 絕對路徑 ---- - 相對路徑 ---- - pwd - print working directory ---- - ls ---- - ls -a - ls -l ---- - ls -al - ll ---- - mv ---- - cp ---- -cat -tac ---- vim and cheatsheet https://vim.rtorr.com/lang/zh_tw ---- - more - less the less is more ---- - 連結指令 - input and output stream > file < - chain | - linux 的強大在於組合技 ---- - rm 檔案 - rmdir 路徑 ---- - 自爆按鈕 - 除在虛擬環境外 請勿模仿風險自負 ---- - rm -rf 檔案 - rm -rf / ---- - 試爆現場 [Running rm -rf / on Linux](https://www.youtube.com/watch?v=D4fzInlyYQo) [What happens when you sudo rm -rf / your machine?](https://www.youtube.com/watch?v=BhbLx0limX8) [Destroying OS X Yosemite!](https://www.youtube.com/watch?v=Vun-7MXK_10) ---- - yes - yes no --- - curl URL --- ## package mananagement and utilize ---- ### 基本套件使用 ---- - why package managemer? 套件管理器是幹嘛用的? ---- - 用來輕鬆安裝、升級或移除外部的程式 ---- - 處理套件相依性 ---- - 保持可維護性 ---- - 安全性 方便通靈 ---- - 越少不必要的套件,越少多餘的風險 ![](https://i.imgur.com/u8VTIgk.png) - 來源 https://twitter.com/SwiftOnSecurity/status/545738504886448128 ---- ## [List of software package management systems](https://en.wikipedia.org/wiki/List_of_software_package_management_systems) ---- ## OS based ---- - unix like - apt,rpm,dpkg,brew,pacman ---- - macOS - brew,macport ---- - windows - cywin,brew ---- ## Application-level Dependency managers ---- - python ![](https://imgs.xkcd.com/comics/python_environment_2x.png =500x) ---- - node.js ![](https://devhumor.com/content/uploads/images/June2020/node_modules_github.jpg =500x) ---- - 套件 binary package 發布 ---- - sudo ![](https://i.imgur.com/Vb27ChP.png) ---- - protect your sudo ---- - fortune - cowsay --- ### master utilize - man from rtfm to tldr ---- - help - info ---- - man - man man - man 7 man ---- - RTFM (read the f*king mannaul) ![](https://i.imgur.com/nnQY66m.jpg =400x) ---- - 因為這是完整了解整個系統最好的做法,對所有學習 linux shell 的人建議通常是 ![](https://i.imgur.com/Ba57pt3.png =400x) ---- - 這也成為了網路戰人,最好的詞 ![](https://i.imgur.com/R8aIMlD.jpg =400x) ---- - but ~ ---- - tldr (too long didn't read) ![](https://i.imgur.com/aox8XCM.jpg =400x) ---- - book: how to read a book ---- - more advance tool - tmux - gnuplot ---- - all shell kind - unix - bash - zsh - fish ---- - Poxis standard --- ## scripting shell, files. ---- ### data wrangling - pipeline ---- - regex ---- - find sed awk ---- ### file type and scripting - permission to execute - files type and shebang - brew install code - example logic bomb - sehll fork bomb ``` :(){ :|:& };: ``` https://www.cyberciti.biz/faq/understanding-bash-fork-bomb/ --- ## FHS configure, log prompt in dot files ### 結構 - FHS - everything is a file in linux ## 檔案系統階層標準 (FHS) - bin - 一定要有的sh - boot - boot loader / EFI - dev - device files - etc - 設定相關 config - lib - 必要的程式 library - gnu, glibc, ld - 一些共用 library - media - mnt - 可留白,需要掛載使用 - opt - run - 系統正在執行的 process - sbin - read-only - for 系統管理員使用 - srv - tmp - tmpfs - usr - In the original Unix implementations, /usr was where the home directories of the users were placed (that is to say, /usr/someone was then the directory now known as /home/someone). In current Unices, /usr is where user-land programs and data (as opposed to 'system land' programs and data) are. The name hasn't changed, but it's meaning has narrowed and lengthened from "everything user related" to "user usable programs and data". As such, some people may now refer to this directory as meaning 'User System Resources' and not 'user' as was originally intended. - [wiki](https://zh.wikipedia.org/wiki/%E6%96%87%E4%BB%B6%E7%B3%BB%E7%BB%9F%E5%B1%82%E6%AC%A1%E7%BB%93%E6%9E%84%E6%A0%87%E5%87%86): 注意不是user的縮寫,而是"Unix Software Resource"的縮寫。 - var - dot files - log ### 自訂 - env variable - ps1 - config - login like Tony Stark - prompt ## next week premier about linux structure part intro bootloader, kernel, rootfs , toolchain process and service how to manage it? # reference page ## 如果有多出來的時段或是有人提到感興趣,將能觸發以下章節 *** date time? *** file everything is a file in linux *** regex *** shell 的基本語法 變數、陣列、迴圈、判斷式以及函式? *** script shell too much? guide read code *** shell example in ? prompt is best example *** IO c? c++ standard guide read posix leave for next time more chapter
{"metaMigratedAt":"2023-06-15T11:38:21.437Z","metaMigratedFrom":"Content","title":"第一章 shell","breaks":true,"contributors":"[{\"id\":\"e597b683-1086-4827-a909-b042866d09c2\",\"add\":8124,\"del\":1038}]"}
    480 views
   Owned this note