# Linux常用指令 Windows下安裝git時會另外安裝**bash**(預設選項會是打勾安裝), 這個bash小黑窗是讓你可以在Windows環境下也能使用linux基本指令, 另外bash內有附**vim**這個指令版的文字編輯器。 ## 快捷鍵 * `ctrl + c` - 中斷目前畫面上的操作(中斷前景程序process) * `ctrl + l` - 清畫面 * `ctrl + d` - 離開(等同輸入exit+enter) * `ctrl + z` - 將目前畫面上的操作切換到背景(不中斷操作) * 用法: [Linux 切換 process 至背景或前景作業 – Ctrl + z](https://dinos80152.wordpress.com/2015/03/04/linux-%E5%88%87%E6%8F%9B-process-%E8%87%B3%E8%83%8C%E6%99%AF%E6%88%96%E5%89%8D%E6%99%AF%E4%BD%9C%E6%A5%AD-ctrl-z/) * [Linux中ctrl-c, ctrl-z, ctrl-d 區別](https://blog.csdn.net/mylizh/article/details/38385739) ## 基本指令 | Windows | MacOS / Linux | 說明 | | -------- | -------- | -------- | | cd | cd | 切換目錄 | | cd | pwd | 取得目前所在的位置 | | dir | ls | 列出目前的檔案列表 | | mkdir | mkdir | 建立新的目錄 | | 無 | touch | 建立檔案 | | copy | cp | 複製檔案 | | move | mv | 移動檔案(也可以用來更換檔名) | | del | rm | 刪除檔案 | | cls | clear | 清除畫面上的內容 | | ipconfig | ifconfig | 查ip | * `ls` * `ls -a` - 顯示`.`開頭的檔案或資料夾,例如`.git/` * `ls -l` - 顯示檔案權限 * `ll` 是 `ls -l` 的別名 * `ls -al` - 指令可以混用 * `mv` * `mv a.htm b.htm` - mv可以這種方式來更換檔名 * `rm` * `rm -r mydir` - 刪除底下有檔案的資料夾 * `-r` - recursive 遞迴處理 * `rm -rf mydir` - 直接刪不跳訊息(-f要小心使用) * `cd` * `cd /` - 切換到系統根目錄 * `cd ~` - 切換到使用者根目錄 ## find 搜尋檔案 在`/home`目錄搜尋`gtwang.txt`,且不分大小寫 ```shell= find /home -iname gtwang.txt ``` * [Unix/Linux 的 find 指令使用教學、技巧與範例整理](https://blog.gtwang.org/linux/unix-linux-find-command-examples/) ## vi / vim : 指令介面的文字編輯器 **vi**是所有 UNIX, Linux 系列的系統都會預設安裝的指令介面的文字編輯器 **vim**是他的強化版,但不一定是系統預設安裝,另外vim有出視窗版的文字編輯器(windows也可用) 這邊主要是講指令介面模式 * 模式切換 * `ESC` - Command mode * `Insert` - Insert mode * insert mode - 插入模式 (通常是用這個) * replace mode - 取代模式 ### Command mode * 基本 * `:wq` - 寫入/存檔並離開 * `:q` - 離開 * `:q!` - 強制離開不存檔 * `:w` - 寫入/存檔 * `/` - 搜尋 * `:set` * `:set fileencoding=utf-8` - 強制使用utf-8碼格式 * `:set number` - 顯示行數 * `:set number!` - 關閉行數 ## Service 列出運行中的服務 ```shell= service --status-all ``` 狀態 ```shell= service nginx status ``` 啟動/停止/重啟 ```shell= service mysql start service mysql stop service mysql restart ``` * [How to start, stop, and restart MySQL database server?](https://tableplus.io/blog/2018/10/how-to-start-stop-restart-mysql-server.html) * [Red Hat / CentOS Check and List Running Services Linux Command](https://www.cyberciti.biz/faq/check-running-services-in-rhel-redhat-fedora-centoslinux/) ## 參考資料 * [Git 教學:終端機及常用指令介紹](https://gitbook.tw/chapters/command-line/command-line.html) * [VI (VIM) FOR WINDOWS USERS](https://cognitivewaves.wordpress.com/vi-editor/) * [Linux 的 touch 指令用法教學與範例](https://blog.gtwang.org/linux/linux-touch-command-tutorial-examples/) * [Linux ls和ll命令](https://blog.csdn.net/cgzhello1/article/details/7839534) ###### tags: `linux`
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.