Instead of ls cygwin already has lsattr for this purpose
lsattr — List file attributes
Description
The lsattr program allows to list file attributes, namely DOS attributes, file sparseness, FS level encryption and compression state, as well as directories' case sensitivity setting.
$ lsattr /cygdrive/c
-hs--------- /cygdrive/c/$Recycle.Bin
------------ /cygdrive/c/cygwin64
lsattr: Device or resource busy while trying to open /cygdrive/c/pagefile.sys
------------ /cygdrive/c/PerfLogs
r----------- /cygdrive/c/Program Files
r----------- /cygdrive/c/Program Files (x86)
-h-------n-- /cygdrive/c/ProgramData
------------ /cygdrive/c/Python27
-hs------n-- /cygdrive/c/Recovery
-hs--------- /cygdrive/c/System Volume Information
r----------- /cygdrive/c/Users
------------ /cygdrive/c/Windows
If you need to do somethings on files with or without specific attributes then just use the first field to filter. For example to operate on items with system attribute:
$ for d in $(2>/dev/null lsattr /cygdrive/c | grep -P '^..s' | cut -d' ' -f2); \
do echo "$d"; done
/cygdrive/c/$Recycle.Bin
/cygdrive/c/Recovery
/cygdrive/c/System
You can also use --long to get the long attributes
$ lsattr --long /cygdrive/c
/cygdrive/c/$Recycle.Bin Hidden, System
/cygdrive/c/cygwin64 ---
lsattr: Device or resource busy while trying to open /cygdrive/c/pagefile.sys
/cygdrive/c/PerfLogs ---
/cygdrive/c/Program Files Readonly
/cygdrive/c/Program Files (x86) Readonly
/cygdrive/c/ProgramData Hidden, Notindexed
/cygdrive/c/Python27 ---
/cygdrive/c/Recovery Hidden, System, Notindexed
/cygdrive/c/System Volume Information Hidden, System
/cygdrive/c/Users Readonly
/cygdrive/c/Windows ---
Note that Linux itself also has a similarly named program, but for listing files along with their extended attributes
/snap$ lsattr
--------------e----- ./core20
--------------e----- ./README
--------------e----- ./docker
--------------e----- ./bin
--------------e----- ./auto-cpufreq
--------------e----- ./lxd
--------------e----- ./ccls
--------------e----- ./snapd
--------------e----- ./core
--------------e----- ./core18
/snap$ ll
total 48
drwxr-xr-x 11 root root 4096 Mar 7 21:53 ./
drwxr-xr-x 20 root root 4096 Mar 16 15:55 ../
-r--r--r-- 1 root root 548 Feb 2 00:29 README
drwxr-xr-x 4 root root 4096 Mar 15 03:46 auto-cpufreq/
drwxr-xr-x 2 root root 4096 Mar 17 20:53 bin/
drwxr-xr-x 3 root root 4096 Feb 23 09:19 ccls/
drwxr-xr-x 4 root root 4096 Mar 23 11:36 core/
drwxr-xr-x 4 root root 4096 Feb 23 05:19 core18/
drwxr-xr-x 3 root root 4096 Mar 7 21:52 core20/
drwxr-xr-x 3 root root 4096 Feb 22 18:57 docker/
drwxr-xr-x 4 root root 4096 Mar 17 20:53 lxd/
drwxr-xr-x 4 root root 4096 Mar 24 04:17 snapd/