本篇體驗Git Bash在Windows操做系統上的用法。
什麼是Bash?
是一個Shell環境,Bourne Again Shell的縮寫。
安裝git for windows
→ http://git-for-windows.github.io/
→ Download,選擇一個合適的版本
→ 安裝
→ 安裝完後有Git Bash, Git CMD, 和 Git GUI這個三個應用程序
→ 運行Git Bash,檢查當前版本
git version
→ 退出
exit
安裝Notepad++
→ notepad-plus-plus.org
→ download,選擇合適的版本
→ 安裝
在Bash中打開Notepad++
→ 找到notepad++的應用程序文件
通常在C:\Program Files(x86)\Notepad++中,把C:\Program Files(x86)\Notepad++賦值
→ 右鍵"個人電腦",點擊"高級系統設置", 點擊"環境變量", 雙擊Path,把;C:\Program Files(x86)\Notepad++加到最後,點擊"肯定"
→ 運行Git Bash
→ notepad++
這樣,在Bash中就打開notepadd++了。
顯示查看當前目錄
→ 運行Git Bash
→ 查看當前目錄
pwd
顯示/c/Users/Darren,其中/c/至關於C:\,
→ 列出當前文件夾下的全部文件
ls
或
ls -l
更換當前目錄
→ 運行Git Bash
→ 導航到其它目錄
cd Videos/
→ 退回到上一級
cd ..
→ 導航到My Documents目錄
cd My\ Documents/
→ 退回三級
cd ../../../
→ 回到主目錄
cd ~
→ 導航到一個絕對位置上的目錄
cd /c/Windows/System32/
查看命令出處
→ 查看ls命令的出處
whick ls
顯示/bin/ls
顯示打印
→ 顯示打印環境變量
echo $PATH
查看文件內容
→ 查看一個文件內容
cat test.txt
→ 查看一個文件內容並編輯
less test.txt
建立、重命名、移動、刪除文件
→ 建立一個空文件
touch demo.txt
→ 重命名一個文件
mv demo.txt demo-1.txt
→ 刪除已知文件
rm demo-1.txt
建立、刪除目錄
→ 建立目錄
mkdir projects
→ 刪除目錄
rmdir projects
→ 建立多級目錄
mkdir projects/client-a/awesome-web-project/
→ 刪除多級目錄
rm -rf projects/
清空和退出
→ 清空內容
clear
→ 退出控制檯
exit
控制檯打印信息輸出到文件
→ 打印信息輸出追加到建立文件
echo "hi" >> demo.txt
→ 打印信息輸入重寫已知文件
echo "hello" > demo.txt
執行Bash腳本
→ 查看bash安裝在哪裏
which bash
顯示:/bin/bash
→ 使用notepad++建立打開一個文件
notepad++ example.sh
→ 輸入命令
#!/bin/bash
echo "hi, everyone"
git