Windows Equivalent of the 'ls', 'which' and 'ln' commands

avatar
Borislav Hadzhiev

Last updated: Apr 4, 2024
9 min

banner

# Table of Contents

  1. Windows Equivalent of the 'ls' command - CMD & PowerShell
  2. Windows: Equivalent of the 'which' command - CMD & PowerShell
  3. The Windows equivalent of the 'ln' command (symbolic link)

# Windows Equivalent of the 'ls' command - CMD & PowerShell

The Unix ls command is used to list the names of the files and subdirectories in a specific directory.

The dir command is the Windows equivalent of the ls command. The dir command displays a list of a directory's files and subdirectories. The command also displays the date and time each file or directory was modified.

cmd
dir

Here is an example output of running the dir command in CMD.

using dir command in cmd

You can also use the wildcard character * with the dir command to substitute for any string of characters.

cmd
dir *.txt

using dir command with wildcard

The command in the example lists all files in the current directory that have an extension that begins with .txt extension, e.g. a.txt, b.txt, c.txt1, etc.

Here is another example of using the wildcard * character with the dir command.

cmd
dir abc*.txt

dir command wildcard begin and extension

The command lists all files in the current directory that begin with abc and have an extension that begins with .txt.

You can use the dir/? command to print all of the parameters that can be passed to the dir command.

cmd
dir/?

Alternatively, you can view the syntax and the parameters for the dir command in this section of the docs.

The PowerShell equivalent of the ls command is Get-ChildItem.

# Windows equivalent of the ls command in PowerShell

The Windows equivalent of the ls command in PowerShell is the Get-ChildItem command.

The Get-ChildItem command lists the filenames and the subdirectory names in the current directory.

PowerShell
Get-ChildItem

windows powershell get childitem command

Note that there is also an ls alias for the Get-ChildItem command in PowerShell.

PowerShell
ls

using ls alias in powershell

If you need to open PowerShell in a specific folder:

  1. Open the folder in a window.
  2. Press Shift and right-click in Explorer.

windows open powershell window here

  1. Click on "Open PowerShell window here".
  2. Run the ls or Get-ChildItem command.
PowerShell
Get-ChildItem ls

You can use the -Path parameter to specify a path. Wildcards are accepted and the default location is the current directory.

shell
Get-ChildItem -Path 'C:\Users\Public\bobbyhadz\'

get childitem with path parameter

The command lists the files and directories under the path C:\Users\Public\bobbyhadz.

Make sure to update the path according to your requirements.

The output includes information about the mode, when the file or directory was last updated, its size, etc.

If you only want to get the names of the files and directories, use the -Name parameter.
shell
Get-ChildItem -Path 'C:\Users\Public\bobbyhadz\' -Name

only get name of files and directories

You can use the Get-Help Get-ChildItem command to display the help page of Get-ChildItem with information about the syntax, the command's aliases and some helpful remarks.

PowerShell
Get-Help Get-ChildItem

You can also check out the command's syntax and some examples in the official docs.

Alternatively, you can use the ls command in Git Bash on Windows.

If you already have git installed, you can search for Git Bash and use the ls command, otherwise, you have to install git first.

# Running the ls command in Git Bash

To download git and be able to use Git Bash:

  1. Open the git downloads page and download the installer for Windows.
  2. Start the installer.
  3. You will be prompted to select a destination location. You can leave the default option and click Next.

git select destination location

  1. You will be prompted to select components on the next screen. Leave the default options and click Next.

git select components

  1. Click Next on the screen that prompts you to "Select Start Menu Folder".

  2. On the next screen, you can choose the default editor for Git, e.g. Notepad, Notepad++ or any other editor you prefer.

choose git default editor

  1. On the "Adjust the name of the initial branch in new repositories screen", click Next.

adjust name of initial branch

  1. On the "Adjust your PATH environment" screen, make sure you have the default option of "Git from the command line and also from 3rd-party software" option selected and click "Next".

adjust your path environment

  1. For all the remaining screens, leave the default option selected and click Next.
  2. Lastly, click on the Install button to install git.

Once you have git installed, click on the Search field, type "Git Bash" and start the application.

search for git bash

Now you can use the ls command directly in Git Bash.

GitBash
ls

using ls command in git bash

If you need to open Git Bash in a specific folder:

  1. Open the folder in a new window.
  2. Right-click in Explorer.

open git bash in folder

  1. Click "Git Bash Here".

Now you can use the ls command to display a list of the directory's files and subdirectories.

GitBash
ls

# Windows: Equivalent of the 'which' command - CMD & PowerShell

The Unix which command searches the $PATH environment variable and returns the path to the specified executable.

The where command is the Windows equivalent of the which Unix command.

The where command displays the location of all files that match the given search pattern, not just executable files.

cmd
where node where python

Make sure to replace the node and python placeholders with the name of your specific command.

windows where command in cmd

You can also use wildcards when issuing the where command.

cmd
where pyt*

windows where command with wildcards

The command in the example finds all files in your %PATH% environment variable and the current directory whose names start with pyt.

You can use the where /? command to display a short description of the command, its parameter list and a couple of examples.

cmd
where /?

where help page

You can also check the parameters the where command takes and some examples in the official docs.

# Windows equivalent of the which command in PowerShell

The Get-Command is the Windows equivalent of the Unix which command in PowerShell.

The command can be used to get the command type, the name and the path to the specified executable.

PowerShell
Get-Command node | Format-Table CommandType, Name, Definition
Make sure to replace node with your specific executable.

windows powershell get command

You can also specify the -All parameter when issuing the command.

PowerShell
Get-Command node -All | Format-Table CommandType, Name, Definition

The -All parameter of Get-Command can be used to show all instances of the specified command on the local computer.

For example, this would be useful if you have multiple instances of node installed.

You can also use wildcards with Get-Command.

PowerShell
Get-Command no* | Format-Table CommandType, Name, Definition

powershell get command using wildcards

The command displays the command type, the name and the path to the executables whose names start with no.

You can use the Get-Help Get-Command command to display the help page of Get-Command with information about the syntax, the command's aliases and some helpful remarks.

PowerShell
Get-Help Get-Command

You can also check out the command's syntax and some examples in the official docs.

Alternatively, you can use the which command in Git Bash on Windows.

If you already have git installed, you can search for Git Bash and use the which command, otherwise, you have to install git first.

# Using the which command in Git Bash on Windows

To download git and be able to use Git Bash:

  1. Open the git downloads page and download the installer for Windows.
  2. Start the installer.
  3. You will be prompted to select a destination location. You can leave the default option and click Next.

git select destination location

  1. You will be prompted to select components on the next screen. Leave the default options and click Next.

git select components

  1. Click Next on the screen that prompts you to "Select Start Menu Folder".

  2. On the next screen, you can choose the default editor for Git, e.g. Notepad, Notepad++ or any other editor you prefer.

choose git default editor

  1. On the "Adjust the name of the initial branch in new repositories screen", click Next.

adjust name of initial branch

  1. On the "Adjust your PATH environment" screen, make sure you have the default option of "Git from the command line and also from 3rd-party software" option selected and click "Next".

adjust your path environment

  1. For all the remaining screens, leave the default option selected and click Next.
  2. Lastly, click on the Install button to install git.

Once you have git installed, click on the Search field, type "Git Bash" and start the application.

search for git bash

Now you can use the which command directly in Git Bash.

GitBash
which node

using which command on windows in git bash

If you need to open Git Bash in a specific folder:

  1. Open the folder in a new window.
  2. Right-click in Explorer.

open git bash in folder

  1. Click "Git Bash Here".

Finally, issue the which command.

GitBash
which node

# The Windows equivalent of the 'ln' command (symbolic link)

The Windows mklink command is the equivalent of the Linux/Unix ln command. The mklink command creates a directory or a file symbolic link.

To create a symbolic link, you must start CMD as an administrator.

To open CMD as an administrator:

  1. Click on the Search bar and type CMD.

  2. Right-click on the Command Prompt application and click "Run as administrator".

run cmd as administrator

The mklink command is used to create a directory or a file symbolic or hard link.

Here is an example that creates a directory symbolic link.

The following command creates a symbolic link named MyFolder from the root directory to the \Users\Alice\Documents directory.

cmd
mklink /d \MyFolder \Users\Alice\Documents

windows create symbolic link

The following command creates a hard link named Myfile.file to \Alice\Documents\example.file.

cmd
mklink /h \MyFile.file \Alice\Documents\example.file

You can check out the parameters the mklink command takes and other examples in this section of the docs.

Alternatively, you can run the ln command in Git Bash by installing git on your Windows machine.

If you already have git installed:

  1. Search for "Git Bash".
  2. Open Git Bash as an administrator.
  3. Use the ln command.

Otherwise, you have to install git first.

# Running the ln command on Windows in Git Bash

To download git and be able to use Git Bash:

  1. Open the git downloads page and download the installer for Windows.
  2. Start the installer.
  3. You will be prompted to select a destination location. You can leave the default option and click Next.

git select destination location

  1. You will be prompted to select components on the next screen. Leave the default options and click Next.

git select components

  1. Click Next on the screen that prompts you to "Select Start Menu Folder".

  2. On the next screen, you can choose the default editor for Git, e.g. Notepad, Notepad++ or any other editor you prefer.

choose git default editor

  1. On the "Adjust the name of the initial branch in new repositories screen", click Next.

adjust name of initial branch

  1. On the "Adjust your PATH environment" screen, make sure you have the default option of "Git from the command line and also from 3rd-party software" option selected and click "Next".

adjust your path environment

  1. For all the remaining screens, leave the default option selected and click Next.
  2. Lastly, click on the Install button to install git.

To run Git Bash as an administrator:

  1. Click on the Search bar and type "Git Bash".
  2. Right-click on the "Git Bash" application and click "Run as administrator".

run git bash as administrator

Now you can use the ln command directly in Git Bash.

GitBash
ln -s my_file.txt my_symbolic_link.txt ln -l my_symbolic_link.txt

windows git bash use ln command

# Additional Resources

You can learn more about the related topics by checking out the following tutorials:

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.