朱栢逸
    • 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 New
    • Engagement control
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: 前端 --- # Linux Cheatsheet 指令大全 ## 檔案讀寫 * `source [file]` 讀取檔案內容當作指令 * `[command] < [file]` 讀取檔案內容作為指令參數 * `[cmd1] & [cmd2]` 指令1執行完接指令2 * `[cmd1] && [cmd2]` 指令1執行成功後才接指令2 * `[cmd1] || [cmd2]` 指令1執行失敗後才接指令2 * `[cmd1] < ([cmd2])` 用指令2的stdout輸入到指令1 * `[cmd1] | [cmd2]` 將指令1的stdout輸入到指令2 * ```[command] `cmd2` ``` 也可以改用backtick達到上面方法 * `[command] > [file]` 輸出stdout到檔案裡(覆寫) * `[command] >> [file]` 輸出stdout到檔案裡(添加) * `[command] 2> [file]` 輸出stderr * `[command] 1>&2` 輸出stdout到輸出stderr的檔案 * `[command] 2>&1` 輸出stderr到輸出stdout的檔案 * `man [command]` 查看指令使用手冊 * `pwd` 當前資料夾位置 * `ls -R [path]` 遞迴顯示所有子項目 * `cd /` 到系統根目錄 * `cd ~` 到用戶根目錄 * `cd ..` 回上一層 * `touch [path]` 新增檔案或更新最後修改日期 * `head [file] [lines]` 讓我看看開頭 * `more [file]`或`cat [file]]` 讓我看看全部內容 * `tail [file] [lines]` 讓我看看結尾 * `cat [file] | grep [keyword]` 搜尋內容 * `awk '[regexp]' [file]` 用正規表達式爬出內容 * `file [file]` 檢視檔案型態 * `tree` 檢視資料夾結構 * `less [file]` 互動式檢閱檔案內容 * `nano [file]` 編輯檔案內容 * `find [path] [keyword]` 搜尋檔案 * `locate [file]` 搜尋檔案位置 * `cp -r [old_path] [new_path]` 複製檔案 * `mv [old_path] [new_path]` 移動或重新命名 * `mkdir [path]` 新增資料夾 * `rmdir [path]` 移除資料夾 * `rm -rf [path]` 移除所有東西 * `ln -s [file1] [file2]` 同步檔案內容 * `diff [file1] [file2]` 比對檔案內容 * `export $[variable]` 設定變數內容 * `echo $[variable]` 讓我看看變數內容 * `clear` 清空終端機 * `rsync [local_path] [remote_path]` 更新遠端檔案 ## 背景服務 * `nohup [command]` 在背景中執行指令 * `systemctl [restrat|reload|status] [service]` 服務管理 * `service [service] [restrat|reload|status]` 服務管理v2 * `jobs` 查看背景工作 * `bg` 將前台工作調至背景執行 * `fg` 將背景工作調至前台執行 * `lsof` 列出背景工作開啟中的檔案 * `ps aux`或`ps -ef` 列出所有執行緒 * `top` 列出作用中的執行緒 * `htop` 列出作用中的執行緒(human readable版) * `kill [PID]` 停止執行by索引 * `pkill [name]` 停止執行by名稱 * `killall [keyword]` 停止執行by開頭名稱 * `crontab -e` 設定排程 ## 系統與硬體 * `uname -a` 系統版本 * `uptime` 系統使用時間總計 * `history` 使用過的指令 * `lsmod` 查看所有模組 * `modinfo [module]` 查看模組詳細資訊 * `modprobe [module]` 載入模組到內核(kernel) * `date` 現在日期時間 * `date +'%Y/%m/%d %H:%M:%S'` 輸出格式化日期時間 * `date -d '2022-01-01' +'%Y/%m/%d %H:%M:%S'` 字串轉格式化日期時間 * `cal` 日歷 * `bc` 內建小算盤 * `dmesg` 開機資訊 * `reboot` 重新啟動 * `poweroff`或`shutdown` 關機 * `last reboot` 重啟紀錄 * `iostat` I/O數據 * `vmstat` 虛擬記憶體使用數據 * `mpstat` CPU執行數據 * `df -h` 硬碟狀態(h=human readable;m=MB;g=GB) * `watch df -h` 監測硬碟使用狀態 * `du -sh` 當前資料夾使用硬碟總容量 * `du -ah` 資料夾下所有檔案硬碟容量 * `free -h` 記憶體狀態 * `fdisk -l` 硬碟切割狀態 * `lspci -tv` 列出PCI裝置 * `lsusb -tv` 列出USB裝置 * `dmidecode` 列出DMI/SMBIOS * `boisdecode` 列出BIOS * `lscpu` 列出CPU規格 * `lshw` 裝置管理員 * `ifconfig` 網路介面 * `hdparm -I /dev/disk` 查看硬碟規格 * `hdparm -tT /dev/disk` 查看硬碟讀寫效能 ## 網路 * `apt-get install net-tools` 安裝網路工具(ubuntu) * `ufw [allow|deny] [service|port]` 簡易防火牆設定 * `iptables` 進階IP設定 * -A(append)添加設定,如INPUT * -i(interface)介面選項,如eth0, lo, ppp0 * -p(protocol)協定類別,如tcp, udp, udplite, icmp, sctp, icmpv6 * -s(source)來源IP位置 * -dport(destination port)連接埠,如22(SSH), 443(https) * -j(target)目標對策,如ACCEPT, DROP, RETURN * -F(flush)移除所有設定 * -L(list)列出所有設定 * -D(delete)刪除某編號的設定 * `tcpdump` 查詢封包流量 * `netstat -tupln` 查看port使用狀況 * `nslookup [domain]` 查看網域資訊 * `curl -X POST -H 'Content-Type: application/json' -d '{"key":"value"}' [url]` 發送請求 * `wget -O [path] [url]` 下載檔案 * `ping [url]` 顯示ICMP發送請求結果 * `whois [domain]` 查詢網域所有人 * `dig [domain]` 查詢DNS設定 * `ssh-keygen -R` 產生本機端公私鑰 * `ssh [user]@[ip]` 連線到遠端主機 * `nano /etc/ssh/sshd_config` 編輯連線設定 * `scp [path] [user]@[ip]:[path]` 複製檔案到遠端主機 * `mail -s 'subject' -c 'cc_address' -b 'bcc_address' 'to_address'` 寄出郵件 ## 權限 * `whoami` 我誰!!! * `last` 上次登入人員 * `who` 誰正在系統裡 * `w` 查看線上人員 * `finger [user]` 查看某位用戶 * `adduser [user]` 新增用戶 * `passwd -l '[user]'` 修改用戶密碼 * `userdel -r '[user]'` 移除用戶 * `groupadd [group]` 新增群組 * `usermod -a -G [group] [user]` 把用戶加到群組 * `deluser [user] [group]` 把用戶從群組移除 * `delgroup [group]` 刪除群組 * `su - [user]` 切換身分 * `ls -l` 顯示檔案權限 * 權限分類:r(read)、w(write)、x(read+write)、-(none) * 代碼組成:User3碼+Group3碼+Other3碼,如-rwxrw-r-- * 數字對應:7=rwx、6=rw-、5=r-x、4=r-- * `chmod +[r讀取w寫入x執行] [path]` 修改存取權限 * `chown [user] [path]` 修改用戶所有權 * `chgrp [group] [path]` 修改群組所有權 ## 檔案壓縮(加壓→解壓) * `tar -cf [.tar] [file]` → `tar -xf [.tar] ` * `gzip -xf [file]` → `gunzip -xf [.gz]` * `tar -zcvf [file]` → `tar -zxvf [.tar.gz]` * `bzip2 -d [file]` → `bunzip2 [.bz]` * `7z -a [.7z] [file]` → `7z -x [.7z]` * `zip -r [.zip] [file]` → `unzip [.zip]` * `rar -a [.rar] [file]` → `rar -e [.rar]` ## git指令 * `git config user.name` 設定用戶名稱 * `git config user.email` 設定用戶郵件 * `git config --global credential.helper store` 記住認證 * `git config core.autocrlf true` 避免跳出crlf的警告 * `git init` 初始化 * `git status` 目前節點與檔案 * `git add .` 添加所有更動 * `git commit -m "提交訊息"` 添加節點 * `git rm --cache file` 移除後來被列為忽略的檔案 * `git log --oneline` 顯示提交歷程 * `git reflog` 顯示歷程(包含不在遠端節點上的本機節點) * `git revert [節點]` 取消節點 * `git reset [節點] --hard` 重置節點 * `git branch -d [分支]` 刪除分支 * `git branch -a` 列出所有分支 * `git checkout [分支]` 移動節點 * `git merge [分支]` 合併節點 * `git rebase [節點]` 將節點添加在最新節點上 * `git remote add [遠端名稱] [遠端網址]` 建立遠端連結 * `git clone [遠端網址]` 下載專案 * `git push [遠端名稱] [分支]` 上傳更新 * `git pull [遠端名稱] [分支]` 下載更新 * `git stash` 封存當前的修改,避免被提交 * `git pop` 打開被封存的修改 ## Docker指令 * `docker images` 顯示已下載容器 * `docker stats` 工作管理員 * `docker rm -f [id]` 強制移除容器 * 安裝postgres * `docker pull postgres` * `docker run -d --name=psql -p 5432:5432 -e POSTGRES_PASSWORD=密碼 postgres` * 開通防火牆,接著用HeidiSQL等GUI工具連線試試 * 安裝gitea * `docker pull gitea/gitea:latest` * `sudo mkdir -p /var/lib/gitea` * -d 背景執行、--name 本機端唯一名稱、-p 連接埠轉址、-v 檔案位置、-e 參數設定 * `docker run -d --name=gitea -p 10022:22 -p 10080:3000 -v /var/lib/gitea:/data gitea/gitea:latest` * `nano /var/lib/gitea/gitea/conf/app.ini`調個`STATIC_URL_PREFIX` ## Postgres安裝 * 啟動postgres docker `docker run --name pg -e POSTGRES_PASSWORD=postgres -p 5432:5432 -d postgres` * 進到docker的postgres操作psql指令 `docker exec -it pg psql -U postgres -d postgres` * 更改密碼 `ALTER USER postgres PASSWORD 'your_new_password';` * 新增用戶 `CREATE USER new_username WITH PASSWORD 'new_password';` * 給權限 ``` GRANT CONNECT ON DATABASE your_database TO new_username; GRANT ALL ON SCHEMA public TO new_username; ``` ## MySQL安裝 * `apt-get install mysql-server net-tools` 安裝資料庫伺服器 * `netstat -tap | grep mysql` 檢驗安裝是否成功 * `nano /etc/mysql/mysql.conf.d/mysqld.cnf` 編輯網域設定 * `bind-address = chuboy.dev` * `mysql -u root -p` 使用root身分登入 * `GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密碼' WITH GRANT OPTION;` * `flush privileges;` 更新權限操作 * `ufw allow mysql` 開通防火牆 * `service mysql restart` 重開治百病 ## SQL基本操作 * constraint: `PRIMARY_KEY | AUTO_INCREMENT | DEFAULT | UNIQUE | NOT_NULL` * `CREATE TABLE [table]([col] [dtype] [constraint]);` * `ALTER TABLE [table] [ADD|ALTER|DROP] COLUMN [col] [dtype] [constraint];` * `DROP TABLE [table];` 移除資料表 * `[TRUNCATE|DELETE FROM] TABLE [table];` 清空資料表 * `SELECT '2330' AS Tic FROM [table] WHERE [col]='' ORDER BY [col] DESC LIMIT [num];` * `UPDATE [table] SET [col]='2330'` * `INSERT INTO [table] VALUES ('2330')` * `DELETE FROM [table] WHERE [col]=''` * `LOAD DATA INFILE '[.csv]' INTO TABLE [table] FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' IGNORE 1 ROWS;`匯入CSV檔(MySQL) * `COPY DB.表格(欄位) FROM '文字檔的路徑' WITH CSV HEADER DELIMITER AS ',';`匯入CSV檔(PGSQL) * `SELECT * FROM [table] INTO OUTFILE '[.csv]' FIELDS TERMINATED BY ',' ENCLOSED BY '' LINES TERMINATED BY '\n';`輸出csv檔 ## 直譯語言打包exe * python * `python -m venv build/env` * `build\env\Scripts\activate` * `pip install pyinstaller fastapi sqlalchemy pydantic uvicorn pyjwt python-multipart itsdangerous httpx` * `pip freeze > requirements.txt` * `pyinstaller main.py --onefile --distpath build` * pip離線部屬 * `pip freeze > requirements.txt` * `mkdir wheels` * `pip download -r requirements.txt -d wheels` * `cp requirements.txt wheels` * `tar -zcf wheels.tar.gz wheels` * `scp wheels.tar.gz user@192.168.0.1:/user/server` * `ssh user@192.168.0.1` * `tar -zxf wheels.tar.gz` * `pip install -r wheels/requirements.txt --no-index --find-links wheels` * javascript * `npm install --global pkg` * `pkg -t node16-win-x64 index.js -o index.exe`

    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