How to create ls in windows command prompt?

前端 未结 19 2266
一向
一向 2020-12-07 08:34

I want to use ls in windows command prompt and make it run the dir command.

How can I do that?

相关标签:
19条回答
  • 2020-12-07 09:22

    I have a solution but it's dirty:

    Create a file named ls.bat containing only "dir".

    Put it in C:\windows\system32 (or any directory in PATH env var).

    That (should) works!

    Edit: Something more consistent: https://superuser.com/questions/49170/create-an-alias-in-windows-xp

    0 讨论(0)
  • 2020-12-07 09:26

    my ls.bat was below

    @dir %*
    

    that can transfer cli args

    ls /b
    ls /w
    

    put it in %windir% or any directory in your %PATH% variable.

    Just make sure you save the file with ANSI encoding :)

    0 讨论(0)
  • 2020-12-07 09:27

    Windows command prompt for Vista/7 will allow NTFS symbolic links, run cmd.exe as administrator then:

    mklink ls %System%\dir.exe
    

    Then set up your PATH environment variable to include the location of the link you just created.

    If you want more than just the 'ls' command, you should look into cygwin.

    EDIT- Just realized dir.exe is not a separate program, so this doesn't really work. But mklink and cygwin are good things to know about.

    0 讨论(0)
  • 2020-12-07 09:27

    Here is my C# source code and binary.

    Just add ls.exe somewhere and add the path to the path environment variable.

    0 讨论(0)
  • 2020-12-07 09:30

    +1 on the post above suggesting to install git for windows and add the directory bin to your path variables.

    Another way I got touch, ls, and a lot of other UNIX commands working in cmd.exe on my Windows 8 and Windows 7 machines.

    Go to the following site to install Cygwin

    https://www.cygwin.com/install.html

    Install the 32 or 64 bit version for your system. The default settings and packages should include what you need so you don't have to change anything once you get to the packages screen.

    After installation, copy the Cygwin folder path to your environment path variables. For example; if you installed cygwin to C:\Cygwin, you will add the following to your environment system path variables:

    ;C:\Cygwin\bin

    On my system I installed the 64bit version and the default folder name and path was C:\cygwin64. So i added the following to my system environment path variables:

    ;C:\cygwin64\bin

    Restart your terminal if it's open. Then type ls and you'll see a directory listing.

    See the following if you are not familiar with setting PATH environment variables:

    Superuser Link 1

    Superuser Link 2

    0 讨论(0)
  • 2020-12-07 09:31

    I recommend the following recipe.

    1. Use DOSKEY and $* to create your ls command.
    2. Make the command persistent by recording it in a .bat/.cmd file and add the path of the file to registry.

    For example, your command may look like
    DOSKEY ls=dir
    DOSKEY sublime="C:\Program Files\Sublime Text 2\sublime_text" $*
    $* is useful for commands that take on arguments. For example, here I like to be able to do sublime my_code.c.

    The registry for cmd is at HKEY_CURRENT_USER -> Software -> Microsoft -> Command Processor. Create a string valued entry called AutoRun with the full path of the file (not the containing folder) such as %USERPROFILE%\custom_command.cmd. Then each time cmd is run, your command will be loaded!

    You can add more useful stuffs to the batch file too. See here for an example template.

    0 讨论(0)
提交回复
热议问题