![如何在 Windows 中將「tree」指令加入到 git-bash?](https://rvso.com/image/1346181/%E5%A6%82%E4%BD%95%E5%9C%A8%20Windows%20%E4%B8%AD%E5%B0%87%E3%80%8Ctree%E3%80%8D%E6%8C%87%E4%BB%A4%E5%8A%A0%E5%85%A5%E5%88%B0%20git-bash%EF%BC%9F.png)
我在 Windows 7 中使用 git-bash。然而
jcollum@DEVELOPER01 ~/Dev/express_coffee
$ tree .
sh.exe": tree: command not found
好吧,所以我沒有這個tree
命令。如何安裝?我找到了一篇文章,但它是針對 macOS 的。
答案1
您也可以"cmd //c tree"
使用 Windows 的tree
解釋:
- 使用“/c”參數啟動 cmd 並運行樹,然後終止
/C 執行字串指定的命令然後終止
(用於轉義的額外斜線)
/a 用於使用 ascii 字元運行,以防顯示不正確。
答案2
我已經從這裡下載了zip檔中的tree.exehttp://gnuwin32.sourceforge.net/packages/tree.htm正如建議的那樣。
然後我將 tree.exe 檔案提取到C:\Program Files\Git\usr\bin
(我已將此資料夾新增至 Windows 路徑以使其與常規 CMD 一起使用,但它也與 GITBash 一起使用)。
我希望這對您有所幫助!
答案3
Windows 中已經有一個 tree 命令 - 唯一的問題是tree.com
git bash 不會自動添加擴展名.com
並執行它。
tab但是,如果您在輸入後按,它會找到它樹或者特雷
要查看您必須使用的文件//f
- 您必須使用//
,否則 bash 會認為它是資料夾名稱
我也曾經//a
顯示過 ascii 行,但你不必使用它
例子:
dean@dean:~/java$ tree
bash: tree: command not found
dean@dean:~/java$ tree.com //a
Folder PATH listing for volume c
Volume serial number is 4E70-B37A
C:.
+---atom
+---sublime
\---vscode
dean@dean:~/java$ tree.com //a //f
Folder PATH listing for volume c
Volume serial number is 4E70-B37A
C:.
+---atom
| test1
|
+---sublime
| test2
|
\---vscode
test3
dean@dean:~/java$
答案4
適用於 Windows 的 Git (https://gitforwindows.org/)(有 Git Bash)但它不包括tree
.tree
可透過pacman
(套件管理器)使用,但僅當您安裝「Git for Windows軟體開發工具包「(滾動到 gitforwindows.org/ 的底部,其中提供了下載安裝程式的鏈接https://github.com/git-for-windows/build-extra/releases/latest)
這就是:“Windows 的 git 中的套件管理?”非常有幫助 https://stackoverflow.com/questions/32712133/package-management-in-git-for-windows
另外,如同上面 SO 中所評論的,他們連結到這個 git for windows 問題 [Pacman 在新的 2.5.2 安裝 #397 上遺失],它不打算包含pacman
在預設安裝中。
無論如何,我安裝了“Git for Windows SDK”,然後在它的 bash 提示符 (SDK-64) 中運行以下命令來安裝當前樹 v1.7.0-1(截至 2018 年 8 月 30 日發布):
[SDK-64: Bash Terminal for Git for Windows SDK]
pacman -S tree
...
Proceed with installation? [Y/n] Y
在我的系統上,Git for Windows SDK 安裝在: 下C:\git-sdk-64
,因此從我的 Git for Windows Bash shell(未安裝樹)中,我將其透過 tree.exe 複製到它的 /usr/bin 目錄,例如
[MINGW64: Bash Terminal for Git for Windows]
cd /usr/bin
cp /c/git-sdk-64/usr/bin/tree.exe .
現在我可以tree
從兩個 Git Bash shell 運行 v1.7.0。
因此,為了讓其他人(也許還有我自己)在未來的電腦上使用起來更加容易,我透過在 Windows SDK Bash 終端機的 Git 中執行以下命令來查看從哪裡pacman
取得套件:tree
$ pacman -S --info tree
Repository : msys
Name : tree
Version : 1.7.0-1
Description : A directory listing program displaying a depth indented list of files
Architecture : x86_64
...
關鍵是,這是pacman
從“msys”存儲庫中獲取它(僅供參考:即使它說 msys,它實際上正在使用 msys2),所以我查看了/etc/pacman.d/mirrorlist.msys
第一個鏡像指向http://repo.msys2.org/msys/$arch/
因此,下次您想要 Windows 版 Git 中沒有的套件時,您可以從以下位置下載它們:http://repo.msys2.org/msys/x86_64/(對於 64 位元)或來自http://repo.msys2.org/msys/i686/(32 位元)
例如tree v1.7.0-1的直接下載鏈接
- 64 位元:http://repo.msys2.org/msys/x86_64/tree-1.7.0-1-x86_64.pkg.tar.xz
- 或者https://sourceforge.net/projects/msys2/files/REPOS/MSYS2/x86_64/tree-1.7.0-1-x86_64.pkg.tar.xz
- 32 位元:http://repo.msys2.org/msys/i686/tree-1.7.0-1-i686.pkg.tar.xz
- 或者https://sourceforge.net/projects/msys2/files/REPOS/MSYS2/i686/tree-1.7.0-1-i686.pkg.tar.xz