63

When I have hidden files, like dotfiles or a .git directory: How can I list those files and directories in Powershell?

Neither Get-ChildItem, dir nor ls seem to show them.

fuma
  • 5,067
  • 4
  • 35
  • 39
  • 1
    Dotfiles are not hidden in Windows. The convention in Unix world is that, say, `ls` doesn't show those per default. In Windows, file attributes are used instead. These can be modified with `attrib.exe` or via Explorer, when its configured to show hidden items. – vonPryz Jun 12 '18 at 12:47
  • 1
    You can alter the attributes without resorting to any other utility in powershell: `(Get-ChildItem SomeFile.txt).Attributes = 'Hidden'` – EBGreen Jun 12 '18 at 12:54
  • @vonPryz in my FileExplorer > View, I have set "show hidden files". But it is still not listed when using gci/dir/ls. – fuma Jun 12 '18 at 13:23
  • Up to you really. Personally I prefer to delete dupes but it isn't a huge deal as far as I know. – EBGreen Jun 12 '18 at 13:44

1 Answers1

116

In order to show such hidden files, use the -Force parameter for the Get-Childitem command.

Get-ChildItem . -Force

You also can use its aliases, with -Force

dir -Force
ls -Force
gci -Force

Also: if you want to delete fully delete e.g. the .git Directory, you may use Delete-Item .\.git -Force

According to Get-Help Get-ChildItem -Examples "Example 3" this also works: dir -att h, !h

Neuron
  • 5,141
  • 5
  • 38
  • 59
fuma
  • 5,067
  • 4
  • 35
  • 39