I would like to use ls
, and many other Linux tools, from the command line on Windows 10. I know that there is GnuWin32 and other binary replacements, but none of those works as elegantly as the Windows Subsystem for Linux (WSL); including the update mechanisms.
With WSL, one can call ls ...
from the command line via bash -c "ls ..."
, which works great. Ideally, however, I would just type ls
on the command line. I can create an ls.bat
which basically does @bash -c "ls %*"
- but I would have to do that for every single command I want to export. Is there a more direct way of exporting ls
(and many others) to the command line?
Apparently this was the most requested feature for WSL, and Microsoft now supports this feature. To use linux commands from within Command Prompt (or PowerShell), just prefix the command with wsl
. So, for example, here's how you run ls
from CMD.
C:\temp> wsl ls
<- contents of C:\temp ->
Or here's how you update package lists.
C:\temp> wsl sudo apt-get update
[sudo] password for username:
Hit:1 http://archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://security.ubuntu.com/ubuntu xenial-security InRelease [94.5 kB]
More details can be found in the official docs. I'm not sure if you are looking for a solution which doesn't involve any kind of prefixing. If that's the case, I don't know of any solution yet.
Microsoft doesn't directly support what you're asking for, however...
CMD /?
informs us of the following two Registry keys: HKey_Local_Machine\Software\Microsoft\Command Processor\AutoRun
and HKey_Current_User\Software\Microsoft\Command Processor\AutoRun
, which (as long as the /D
option wasn't specified) will both be checked for contents to run (in that order) when a new Command Prompt window is opened.If we put these two things together with a FOR
loop, and a nice, easily customizable file in your user folder, we can get a pretty close approximation of what I think you want.
I'm going to put this in HKLM, and reference a file in %USERPROFILE%
, called exportlinuxcommands
, so that it's available to all users, but easily customizable on a per-user basis, as well as only functional for users who set it up. If you only want it for one user, or don't want it to be customizable on a per-user basis, you'll have to modify the instructions a bit.
HKey_Local_Machine\Software\Microsoft\Command Processor
IF EXIST %USERPROFILE%\exportlinuxcommands FOR /F %i in (%USERPROFILE%\exportlinuxcommands) DO @doskey %i=bash -c "%i $*"
as the "Value data".Now you just need to make a file in your %USERPROFILE%
folder (i.e. C:\Users\YourUserName
) called exportlinuxcommands
, with each Linux command you want an alias to on a separate line. For example:
ls
rm
cat
Want to remove one? Remove it from the file, and it won't be there in the next Command Prompt window you open.
Want to add another later? Just add it to the file on it's own line, and the next time you open up a Command Prompt window, it'll be there.
Try to use windowsBash
Run the following command inside Windows Bash to generate shortcuts for commands
wget https://raw.githubusercontent.com/aleppos/windowsBash/master/windowsBash -P /usr/bin && chmod 0777 /usr/bin/windowsBash && windowsBash
Then just add the following directory to your path in Windows * C:\windowsBash
When you want to update the commands list just run the Shell file again
windowsBash
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With