top of page
List files

To list files, use the ls operator. If no arguments are included, you will get the files in your current directory. Otherwise, you will get files in the named directories. You can use "glob" patterns, as in Linux.

M 0.18.3 jao@loon ~/git/marcel$ ls marcel/*.py
-rw-r--r--   jao    jao         652   2020 May 10 15:41:11   __init__.py
-rw-rw-r--   jao    jao        8299   2023 Sep 17 21:44:34   api.py
-rw-rw-r--   jao    jao       19326   2023 Sep 07 20:53:42   argsparser.py
-rw-rw-r--   jao    jao        1817   2023 Sep 07 20:53:42   builtin.py
-rw-rw-r--   jao    jao       19539   2023 Oct 24 09:27:17   core.py
-rw-rw-r--   jao    jao       13314   2023 Oct 25 13:53:07   env.py
-rw-rw-r--   jao    jao        4523   2023 Sep 10 10:16:31   exception.py
-rw-rw-r--   jao    jao        3158   2020 Dec 10 15:58:17   function.py
-rw-r--r--   jao    jao       20752   2020 Dec 18 14:57:05   helpformatter.py
-rw-rw-r--   jao    jao       11452   2023 Sep 10 21:59:52   job.py
-rw-rw-r--   jao    jao        1081   2023 Sep 07 20:53:42   jsonutil.py
-rw-rw-r--   jao    jao        1736   2022 Aug 19 12:43:09   locations.py
-rw-rw-r--   jao    jao       10895   2023 Oct 25 13:53:07   main.py
-rw-rw-r--   jao    jao        6700   2023 Sep 07 20:53:42   multilinereader.py
-rw-rw-r--   jao    jao        2558   2023 Sep 07 20:53:42   nestednamespace.py
-rw-rw-r--   jao    jao        3465   2023 Sep 07 20:53:42   opmodule.py
-rw-rw-r--   jao    jao       39519   2023 Oct 25 13:53:07   parser.py
-rw-rw-r--   jao    jao        3683   2020 Dec 07 15:42:50   picklefile.py
-rw-r--r--   jao    jao        1522   2020 Nov 10 10:19:25   reduction.py
-rw-rw-r--   jao    jao        1207   2020 Oct 27 19:23:44   reservoir.py
-rw-rw-r--   jao    jao        8101   2023 Sep 11 23:00:28   tabcompleter.py
-rw-rw-r--   jao    jao        6006   2023 Sep 10 12:32:29   util.py
-rw-rw-r--   jao    jao         672   2023 Sep 07 20:53:42   version.py

The ls operator produces a stream of File objects. These can be piped to other commands for further processing. For example, this command lists files (-f) recursively (-r), maps each File to a tuple containing the File's extension (e.g. '.py') and the number 1, and then groups by extension and sums up the 1s, to obtain the number of files of each extension. The results are sorted by extension.

M 0.18.3 jao@loon ~/git/marcel$ ls -fr test | map (f: (f.suffix, 1)) | red . + | sort
('', 1)
('.py', 22)
('.pyc', 5)

bottom of page