如何在 Windows 上的 Bash 上打开当前目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40879648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open the current directory on Bash on Windows?
提问by Yass001
I know that in the Mac OS10, people use the open .
command to open the current directory.
我知道在 Mac OS10 中,人们使用open .
命令打开当前目录。
Does anybody please know the appropriate command to do the same task under Bash on Windows?
有没有人知道在 Windows 上的 Bash 下执行相同任务的适当命令?
Cheers!
干杯!
回答by Jake Garbo
Just Type
只需输入
start .
it will open the current the directory folder.
它将打开当前目录文件夹。
回答by Pieter-Uys Fourie
You can now call explorer.exe from the bash subsystem. I've set up an alias to use it. I've added the copy to clipboard alias as well for good measure.
您现在可以从 bash 子系统调用 explorer.exe。我已经设置了一个别名来使用它。我已经将副本添加到剪贴板别名以及很好的衡量标准。
Alias:
别名:
alias open="explorer.exe"
alias pbcopy="clip.exe"
Example:
例子:
cat ~/.ssh/id_rsa.pub | pbcopy
open .
open "D:\Dir"
The open alias plays well with .
, but you'll need to pass it the Windows path if you want to specify a directory.
开放别名与 配合良好.
,但如果要指定目录,则需要将 Windows 路径传递给它。
回答by onoma
Right now Microsoft don't recommend to mix Windows explorer with the bash shell. In latest win10 Insider builds you could use from bash something like this
现在微软不建议将 Windows 资源管理器与 bash shell 混合使用。在最新的 win10 Insider 版本中,您可以从 bash 使用类似这样的内容
cmd.exe /c start .
If you are using Win10 Anniversary Edition you could try installing a Desktop Environment. Start reading this https://github.com/microsoft/bashonwindows/issues/637After that you could open a window with the present folder content with
如果您使用的是 Win10 周年纪念版,您可以尝试安装桌面环境。开始阅读此 https://github.com/microsoft/bashonwindows/issues/637之后,您可以打开一个包含当前文件夹内容的窗口
gnome-open .
回答by nikoskip
I'm using this function:
我正在使用这个功能:
open()
{
explorer.exe `wslpath -w ""`
}
So if you are in /mnt/c/Users/
and would like to open that folder, just type open .
因此,如果您在其中/mnt/c/Users/
并想打开该文件夹,只需键入open .
wslpath
will resolve only paths from the Windows system, be aware. If you are looking to do something like open ~
it will not work, and you will get:
wslpath
将仅解析来自 Windows 系统的路径,请注意。如果你想做类似的事情是open ~
行不通的,你会得到:
wslpath: /home/my-user: Result not representable
wslpath: /home/my-user: Result not representable
Command usage
命令用法
wslpath usage:
-a force result to absolute path format
-u translate from a Windows path to a WSL path (default)
-w translate from a WSL path to a Windows path
-m translate from a WSL path to a Windows path, with ‘/' instead of ‘\'
EX: wslpath ‘c:\users'
A proof that this works:
证明这是有效的:
回答by Martynas Martin
I have added
我已经添加了
alias open='explorer.exe `wslpath -w ""`'
to the .bashrc
file
到.bashrc
文件
opens current folder when typed open
键入时打开当前文件夹 open
I'm using windows ubuntu subsystem.
我正在使用 windows ubuntu 子系统。
回答by rrmikhail
This command should do it:
这个命令应该这样做:
$ explorer
回答by kuroyza
You Can Use the following command:explorer .
您可以使用以下命令:explorer .
回答by Richard Edwards
In WSL2 it looks like the open
command is now doing what start
does in Windows command. I just put an alias in my .bashrc
在 WSL2 中,看起来该open
命令现在正在start
执行 Windows 命令中的操作。我只是在我的 .bashrc 中放了一个别名
start="open"
Now you can do either start .
or open .
depending on your preferences.
现在,您可以根据自己的喜好来做start .
或做open .
。
回答by Damian Rivas
If start .
doesn't work for you, it's essentially the same as running explorer.exe .
so you can create an alias for it which is what I did.
如果start .
对您不起作用,它本质上与运行相同,explorer.exe .
因此您可以为它创建一个别名,这就是我所做的。
alias start="explorer.exe"
Side note: Another useful one to have is BROWSER
. explorer.exe is capable of starting your default web browser. This comes in handy when you run scripts that open a web browser like starting a React.js development server.
旁注:另一个有用的是BROWSER
. explorer.exe 能够启动您的默认网络浏览器。当您运行打开 Web 浏览器的脚本(例如启动 React.js 开发服务器)时,这会派上用场。
export BROWSER="explorer.exe"
回答by roy
start . - this is the equivalent of open . in bash
开始 。- 这相当于 open 。在 bash