2

Compare Cygwin:

$ ls -1 -N /cygdrive/c
$Recycle.Bin
cygwin64
Documents and Settings
pagefile.sys
PerfLogs
Program Files
Program Files (x86)
ProgramData
Recovery
System Volume Information
Users
Windows

With Command Prompt:

> dir /A:-S C:
2018-12-08  10:14 AM    <DIR>          cygwin64
2009-07-13  09:20 PM    <DIR>          PerfLogs
2018-12-15  06:05 PM    <DIR>          Program Files
2018-12-15  05:21 PM    <DIR>          Program Files (x86)
2018-10-31  06:07 PM    <DIR>          ProgramData
2018-11-18  01:10 AM    <DIR>          Users
2018-11-09  08:18 AM    <DIR>          Windows

as can be seen, Command Prompt has a way to exclude system items. Does Cygwin have some way to do this, perhaps with ls or find?

phuclv
  • 30,396
  • 15
  • 136
  • 260
Zombo
  • 1

2 Answers2

1

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/
phuclv
  • 30,396
  • 15
  • 136
  • 260
0

As a workaround, I am using the fd tool:

C:\> fd -d 1
PerfLogs
Program Files
Program Files (x86)
Users
Windows
cygwin64

https://github.com/sharkdp/fd

Zombo
  • 1