Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMCDragonkai/657e940bc3802047ea7b314e80d65d15 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/657e940bc3802047ea7b314e80d65d15 to your computer and use it in GitHub Desktop.
Powershell: File/Directory Attributes on `ls`, `gci`, `dir` or `Get-ChildItem`

File/Directory Attributes on ls, gci, dir or Get-ChildItem

Powershell allows you to use ls (and related) commands to view your files and directories.

# list files/directories at current working directory
ls
# show hidden files and protected operating system files as well!
ls -Force

You may then see output like this:

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d--hsl       30/10/2015   7:09 PM                All Users
d-----       31/07/2016   9:51 PM                CMCDragonkai
d-----       19/05/2016   9:44 PM                cyg_server
d-rh--       19/05/2016   9:36 PM                Default
d--hsl       30/10/2015   7:09 PM                Default User
d-----       19/05/2016   9:43 PM                Default.migrated
d-r---       14/02/2016   4:33 AM                Public
-a-hs-       30/10/2015   6:21 PM            174 desktop.ini

The Mode column is not the same as Linux permissions column when using ls even though it looks deceptively similar.

There are 6 flags in the Mode section: darhsl.

  • d (directory) - The object is a directory.
  • a (archive) - The file is ready for archiving, basically means it can be automatically backed up.
  • r (read-only) - This prevents writing to the file unless the requesting application explicitly requests this write capability. This generally does not apply to directories.
  • h (hidden) - A hidden file or folder.
  • s (system) - This file or folder is considered a protected operating system file. There's an option in the folder view, that allows you to view hidden files but hide protected operating system files.
  • l (reparse point) - This is a NTFS reparse point, which could mean a symlink, shortcut, directory junction points, volume mount points, hard links, or something else.

Not all attributes are represented, as there are more if you run ls | Select Attributes, Name.

Most of these attributes can be changed by going into file properties and viewing the advanced panels.

@MezTemplar
Copy link

These commands have different attributes on different platforms (Windows vs Linux). I found the only way to be consistent is to use gci | Select...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment