PowerShell Command Equivalent to Linux ls

Rohan Timalsina Apr 12, 2022
  1. Use ls Command to List All Files or Directories in Linux
  2. Use Get-ChildItem Cmdlet for PowerShell Equivalent to Linux ls Command
  3. Use ls, dir or gci for PowerShell Equivalent to Linux ls Command
PowerShell Command Equivalent to Linux ls

The ls command in Linux is used to list files and directories. If no directory is specified, it displays all files and directories in the current working directory.

You can perform different files and folders tasks in PowerShell, such as listing, creating, copying, moving, and removing files and folders. Some PowerShell commands function similar to the ls command in Linux, i.e., list files and directories in the directory.

This tutorial will introduce different PowerShell equivalent commands for the Linux ls command.

Use ls Command to List All Files or Directories in Linux

The following command lists all files and directories in Linux and other Unix-based operating systems.

ls

Output:

Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos

You can use the -l option to view the long format output.

ls -l

Output:

total 32
drwxr-xr-x 2 golinux golinux 4096 Apr  5 23:06 Desktop
drwxr-xr-x 2 golinux golinux 4096 Mar 19 20:48 Documents
drwxr-xr-x 5 golinux golinux 4096 Apr  1 07:19 Downloads
drwxr-xr-x 2 golinux golinux 4096 Mar  5 12:35 Music
drwxr-xr-x 2 golinux golinux 4096 Mar  5 12:35 Pictures
drwxr-xr-x 2 golinux golinux 4096 Mar  5 12:35 Public
drwxr-xr-x 2 golinux golinux 4096 Mar  5 12:35 Templates
drwxr-xr-x 2 golinux golinux 4096 Mar  5 12:35 Videos

Use Get-ChildItem Cmdlet for PowerShell Equivalent to Linux ls Command

The Get-ChildItem cmdlet in PowerShell gets the items and child items in one or more specified locations. It shows all files and directories in the specified directory.

When no directory is provided, it displays all files and directories in the current working directory.

Get-ChildItem

Output:

    Directory: C:\Users\rhntm

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----         3/30/2022  11:34 AM         152103 heart_failure.ipynb
-a----         3/28/2022   7:33 AM          12239 heart_failure_clinical_records_dataset.csv
-a----         2/22/2022  11:46 PM             36 hello.txt
-a----          3/8/2022   2:07 PM         780199 house_data.csv

By default, it shows the attributes (Mode), LastWriteTime, file size (Length), and the Name of the given item.

The d and a letters in the Mode denote directory and archive. You will find r for read-only, h for hidden, l for link, and s for system.

The following command lists all files and directories in the directory C:\record. The -Path parameter is used to specify the path.

Get-ChildItem -Path C:\record

Output:

    Directory: C:\record

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         2/23/2022  11:39 PM                New folder
-a----         2/23/2022  10:29 PM              0 books.txt
-a----         2/23/2022  10:29 PM              0 hello.txt

The ls -a command in Linux is used to list files or directories, including hidden files or directories. In PowerShell’s Get-ChildItem, you can use the -Force parameter to view files or directories, including the hidden ones.

Get-ChildItem -Force

Use ls, dir or gci for PowerShell Equivalent to Linux ls Command

The ls, dir, and gci are the built-in aliases of the Get-ChildItem cmdlet. You can run any of the three aliases to list files and directories in PowerShell.

ls C:\record

Output:

    Directory: C:\record

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----         2/23/2022  11:39 PM                New folder
-a----         2/23/2022  10:29 PM              0 books.txt
-a----         2/23/2022  10:29 PM              0 hello.txt

As you can see, you can use the ls command in PowerShell to list all files or directories like in Linux systems.

gci "C:\Program Files"

Output:

    Directory: C:\Program Files

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----          1/6/2022  11:35 AM                AndroidTbox
d-----         10/5/2021  11:13 AM                Application Verifier
d-----          4/6/2022   2:56 AM                ASUS
d-----        11/29/2021   2:30 PM                Audacity

We introduced multiple commands in PowerShell equivalent to the ls command in Linux. Hoping this article helped you with how to list files or directories using PowerShell.

Rohan Timalsina avatar Rohan Timalsina avatar

Rohan is a learner, problem solver, and web developer. He loves to write and share his understanding.

LinkedIn Website

Related Article - PowerShell Command