Glindra
Documentation Index Download
Command Line File Handling and ASCII Tools

d - Directory

Output Control Options

These options control what output is produced, and how it is formatted.

Example (Windows)
> d *** -totals -sort=(size descending)
Example (Linux)
> d '***' -totals -sort=\(size descending\)
Options
Print a grand total for all the files in all the directories.
-totals Just print the total number of bytes for each directory.
-resolution [= size] Print directories and files that are bigger than a certain size. Directories that are smaller than the specified size will not be listed as entries of their own. Instead, the byte total will be added to the size of the parent directory.
-sort [= sort_order] Sorts the files by name (default), extension, size, or date.
-files List the full filenames only, without any information about file sizes or dates, and with no headers or footers. The output will be a list of file names that is suitable for use as input for other programs.
-header Print a header for each new directory that has files in it, and a footer with totals.
-size [= bytesize_syntax] Print the file sizes.
-date [= datetime_syntax] Print the date and time when each file was created.
-name [= filename_syntax] Specify how the file name should be printed (with or without full path, with or without extension, etc.).
-permissions Shows the file access permissions for each file.
-owner Shows the owner of each file.

Not yet implemented

-group Shows the owner group of each file.

Not yet implemented

-grand_total

The -grand_total option prints the total size, the number of files, and in how many different directories they were found.

The option is on by default for normal listings and summaries, but not for -files listings. If you specify the -grand_total option by itself, it will just print the summary, and no file names.

Example (Windows)
How much space does the \WINDOWS directory, and all its subdirectories, occupy on a normal Windows XP machine?

The -grand_total option provides the answer:

> d c:\windows\*** -grand_total

  2.2 Gb       grand total, 15710 files in 485 directories
By using the -grand_total option, we avoid having all the 15,710 files listed, and just get the total.

In this case, the grand total included all subdirectories, as the file specification contained the *** directory wildcard.

To see how much space the \WINDOWS directory itself occupies, without counting what's in the subdirectories, we would write:

> d c:\windows -grand_total

    15.4 Mb    grand total, 244 files in 1 directories


The negative form of the option, -nogrand_total, suppresses the printing of the grand total for normal file listings.

To suppress the totals per directory, use -noheader.

-totals

The -totals option prints a listing with the number of bytes in each directory that matches the file specification. It is most commonly used together the the *** directory wildcard.

Example (Windows)
> d *** -totals
      128 kb   e:\work\basics\
       65 kb   e:\work\Doc\Discussions\
      101 kb   e:\work\Doc\Drafts\
     3.4 Mb    e:\work\Doc\Foreign\STL_doc\
      323 kb   e:\work\Doc\Foreign\
     1.8 Mb    e:\work\Doc\Junk\
      514 kb   e:\work\Doc\Old\
      428 kb   e:\work\Doc\
      215 kb   e:\work\experiment\old\
     2.0 Mb    e:\work\experiment\
     1.9 Mb    e:\work\main\old\
      814 kb   e:\work\main\
       32 kb   e:\work\notes\
       42 kb   e:\work\Proxy\
      371 kb   e:\work\strix\
        6 kb   e:\work\top_down\
      216 kb   e:\work\util\
     1.8 Mb    e:\work\
  ----------
    14.1 Mb    grand total, 626 files in 18 directories


The byte count for each entry in the list is for that directory only, and does not include files in subdirectories. Directories that are empty are not shown in the list, but directories that contain files but have 0 size, perhaps because all the files were subdirectories, are shown.

After the listing of the individual directories, the grand total is printed by default. To suppress this, use -nogrand_total

-resolution [= size]

The -resolution option is used to get a summary of disk space usage.
Hunting for disk space

Even with a quite small directory structure, such as the one shown in the above example for -totals, it is difficult to see at a glance where the big stuff is. For a larger directory structure, or for an entire disk, this format is not practical for hunting disk space.

Using the file selection option -min_size is not a solution, as that option would only limit the files that are included in the totals to individual files that are bigger than the limit. We would not notice directories that contain a large number of files that are each smaller than the limit, but consume a large amount of disk space together.

Sorting the list of directories with the -sort=size option might be helpful, but we would still not immediately see directories that consume a lot of disk space because the are the parents of large trees of subdirectories.

The -resolution option addresses this. It takes size in bytes as value. There is no default value, so you must specify a value, like for example 10mb or 1gb. The permissible formats are described in Parsing Byte Sizes

A directory that does not contain enough big files to get over the resolution threshold is not listed. Instead, the number of bytes that the directory contained is added to the byte count for the parent directory. If the parent directory is over the threshold, perhaps because it could add the bytes from the subdirectory, then the parent directory is listed. The bytes from the subdirectory will be included in its byte count. If the parent directory is too small, even after the addition of the subdirectory, the bytes will be added to the grandparent's byte count, etc. This ensures that every byte found is accounted for somewhere in the totals.

Example 1 (Windows)

Examining the directory structure from the -totals example, with a resolution of 1mb, yields:

> d *** -totals -resolution=1mb
     3.4 Mb    e:\work\Doc\Foreign\STL_doc\
     1.8 Mb    e:\work\Doc\Junk\
     1.5 Mb    e:\work\Doc\***\
     2.3 Mb    e:\work\experiment\***\
     1.9 Mb    e:\work\main\old\
     3.4 Mb    e:\work\***\
  ----------
    14.1 Mb    grand total, 626 files in 18 directories
We now get a clearer picture of where the disk space is spent.

The directory wildcard ***\ at the end of the entry e:\work\Doc\***\ signals that the byte count includes one or more subdirectories.

After the listing of the directory entries, the grand total is printed by default. To suppress this, use -nogrand_total

Example 2 (Windows)

The astute reader will have noticed that the previous example contains both -resolution and -totals. What happens if we omit -totals, and just specify -resolution ?

> d *** -resolution=1mb
     3.4 Mb    e:\work\Doc\Foreign\STL_doc\
     1.2 Mb    e:\work\Doc\Junk\Glindra_old.doc
     2.1 Mb    e:\work\Doc\***\
     2.3 Mb    e:\work\experiment\***\
     1.9 Mb    e:\work\main\old\
     1.8 Mb    e:\work\libglindra.a
     1.7 Mb    e:\work\***\
  ----------
    14.1 Mb    grand total, 626 files in 18 directories
The result is almost, but not quite, the same.

First, the 3.4 Mb that were listed for e:\work\***\ in Example 1, have now been split on two entries, where the new one is e:\work\libglindra.a . This is a single file that was larger than the resolution threshold, so it now appears as an entry of its own. The total byte size for e:\work\***\ has been adjusted down accordingly, to avoid counting the same bytes twice.

Similarly, the file e:\work\Doc\Junk\Glindra_old.doc of 1.2 Mb has been broken out of the e:\work\Doc\Junk\ directory. Since the remaining files in e:\work\Doc\Junk\ were under the threshold of 1 Mb, that byte count is added to the e:\work\Doc\***\ entry instead.

Example 3 (Windows)
So, what is it that takes up so much space in the \WINDOWS directory? Where can we find the culprits?

After making one or two attempts, in order to find a suitable resolution, we get the answer with the following command:

> d c:\WINDOWS\***\ -resolution=50mb
   305.8 Mb    c:\WINDOWS\$NtServicePackUninstall$\***\
    76.7 Mb    c:\WINDOWS\Driver Cache\I386\DRIVER.CAB
    97.5 Mb    c:\WINDOWS\Help\SBSI\Training\WXPPRO\Content\***\
    56.8 Mb    c:\WINDOWS\Help\***\
    56.6 Mb    c:\WINDOWS\INF\
   525.5 Mb    c:\WINDOWS\ServicePackFiles\i386\***\
    68.7 Mb    c:\WINDOWS\SYSTEM32\DLLCACHE\
    57.3 Mb    c:\WINDOWS\SYSTEM32\SPOOL\DRIVERS\W32X86\***\
   633.5 Mb    c:\WINDOWS\SYSTEM32\***\
   314.2 Mb    c:\WINDOWS\***\
  ----------
  2.2 Gb       grand total, 15710 files in 485 directories

-sort [= sort_order]

Determines how the entries that are listed should be sorted.

Example
> d -sort=date
Suboptions
name Sort on directory and name. This is the default sort key.
extension Sort on the extension.
date Sort on the date and time.
size Sort on the size.
ascending Sort in ascending order. This is the default.
descending Sort in descending order.
Example (Windows)
> d ..\strix\fi*.* -sort=date

Directory of e:\work\strix\

         684   25-Nov-2003 15:55:14   fill.hpp
         402   25-Nov-2003 15:55:14   find_balancing_bracket.hpp
        4 kb   25-Nov-2003 15:55:14   find_char.hpp
        2 kb   25-Nov-2003 15:55:15   find_unquoted_string.cpp
         765   25-Nov-2003 15:55:16   find_unquoted_string.hpp
         988    2-Dec-2003 22:54:27   find_string.hpp
        4 kb    2-Dec-2003 23:03:29   find_string.cpp
        2 kb    8-Mar-2004 14:53:43   find_balancing_bracket.cpp
        2 kb    8-Mar-2004 20:22:43   find_unquoted_char.hpp
        4 kb   17-Mar-2004 23:40:24   find_here.hpp
  ----------
       17 kb   total, 10 files
Example (Windows)
It is possible to combine -sort=size with totals, to get a list of directories sorted on size. This can sometimes be useful.
> d *** -totals -sort=(size descending)
     3.4 Mb    e:\work\Doc\Foreign\STL_doc\
     2.0 Mb    e:\work\experiment\
     1.9 Mb    e:\work\main\old\
     1.8 Mb    e:\work\Doc\Junk\
     1.8 Mb    e:\work\
      814 kb   e:\work\main\
      514 kb   e:\work\Doc\Old\
      428 kb   e:\work\Doc\
      371 kb   e:\work\strix\
      323 kb   e:\work\Doc\Foreign\
      216 kb   e:\work\util\
      215 kb   e:\work\experiment\old\
      128 kb   e:\work\basics\
      101 kb   e:\work\Doc\Drafts\
       65 kb   e:\work\Doc\Discussions\
       42 kb   e:\work\Proxy\
       32 kb   e:\work\notes\
        6 kb   e:\work\top_down\
  ----------
    14.1 Mb    grand total, 626 files in 18 directories

-files

If you are using the d command to get a list of files, that you intend to use as input to some other program, the default output format is not very convenient. The directory names are in headers, and there is extra information in front of each filename.

With the -files option, each output line will contain the full name of one file, including the directory. No headings will be printed out, and no information about size or date for each file.

Example (Windows)
> d *.txt -files
e:\work\About.txt
e:\work\notes.txt


The -files option is equivalent to

-noheader -nosize -nodate -nogrand_total
but is more convenient to type.

-header

If -header is specified, the program will print a header with the directory name for each new directory, as well as a footer with the total number of bytes and files for each directory.

If you specify -noheader, these headers and footers will not be printed out. The directory name will appear as part of the name for each file that is listed. <-> The default is -header for normal lists, and -noheader for -files, -totals, and -resolution lists.

Example (Windows)
> d ***\compare*.hpp -nohead
        3 kb   20-Oct-2003 12:24:26   e:\work\basics\compare.hpp
         672   28-Jan-2004 10:55:18   e:\work\basics\compare_same_length.hpp
        7 kb   17-Mar-2004 23:59:48   e:\work\strix\compare.hpp
  ----------
       10 kb   grand total, 3 files in 2 directories


To get rid of the grand total summary at the end, specify -nogrand_total.

> d ***\compare*.hpp -nohead -nogrand
        3 kb   20-Oct-2003 12:24:26   e:\work\basics\compare.hpp
         672   28-Jan-2004 10:55:18   e:\work\basics\compare_same_length.hpp
        7 kb   17-Mar-2004 23:59:48   e:\work\strix\compare.hpp

-size [= bytesize_syntax]

Use -size to print the size of each file, or -nosize to suppress this field.

The field is shown by default for normal listings, but not for -files ones.

Example (Windows)
> d f*.* -nosize

Directory of e:\work\main\

   3-Nov-2004 16:56:54   fi.xyz
   2-Nov-2004 23:26:57   filespec.html

  32 kb total, 2 files
Specifying how the size should be printed

The option can take a value that specifies the exact syntax that should be used for printing size.

See Byte Size Syntax for further information.

-date [= datetime_syntax]

Use -date to print the date and time when each file was created, or -nodate to suppress this field.

The field is shown by default for normal listings, but not for -files ones.

Example (Windows)
> d f*.* -nodate

Directory of e:\work\main\

         367   fi.xyz
       32 kb   filespec.html
  ----------
       32 kb   total, 2 files
Example (Windows)
> d f*.* -files -date
   3-Nov-2004 16:56:54   e:\work\main\fi.xyz
   2-Nov-2004 23:26:57   e:\work\main\filespec.html
Specifying how the date/time should be printed

The option can take a value that specifies the exact syntax that should be used for printing the date and time.

See Date/Time Syntax for further information.

Example (Windows)
> d f*.* -files -date=date_only
            3-Nov-2004   e:\work\main\fi.xyz
            2-Nov-2004   e:\work\main\filespec.html
Example (Windows)
> d f*.* -files -date=(time_only width=0)
  16:56:54   e:\work\main\fi.xyz
  23:26:57   e:\work\main\filespec.html

-name [= filename_syntax]

Specifies how the file name should be printed (with or without full path, with or without the extension etc.).

Example (Windows)
> d -name=(directory noversion)
Example (Linux)
> d -name=\(directory noversion\)
Suboptions
directory Show the directory. This is the default for -files lists.
nodirectory Do not show the directory. This is the default for normal lists.
extension Show the extension. This is the default.
noextension Do not show the extension.
version Show the version number. This is the default.
noversion Do not show the version number.
Example (Windows)
> d f*.* -name=noextension

Directory of e:\work\main\

         367    3-Nov-2004 16:56:54   fi
       32 kb    2-Nov-2004 23:26:57   filespec
  ----------
       32 kb   total, 2 files

-permissions

Use -permissions to print the access permissions of each file. The format for the permissions is the same as the one used by the Linux command ls -l

Default is -nopermissions

Example (Linux)
> d ~ -permissions -nodate

Directory of /home/chris/

       <DIR> drwx------  Desktop
       <DIR> drwxr-xr-x  bin
          12 lrwxrwxrwx  doc
     1.5 Mb  -rwxr-xr-x  hello
         141 -rw-r--r--  hello.cpp
           0 -rw-r--r--  hello.lis
          14 lrwxrwxrwx  linux
  ----------
     1.5 Mb   total, 7 files
Suggested alias
alias dp='d -permissions -nodate'
The alias dp shows the permissions for each file instead of the date and time.


The -permissions option works under Windows as well, but since Windows does not have file permissions in the way that Linux does, the permissions for "group" and "others" are shown as being the same as for "owner". On Windows the x (execute) bit is shown for files that have an extension that is listed in the PATHEXT environment variable, as well as for all directories.