Hi, It recently struck me that a useful option to `du' would be the ability to add up the lengths of files instead of the disc space they occupy. If you agree, please consider the diff below as a way of adding this feature. It patches du.c and fileutils.texi (and nothing else). ttfn/rjk --- fileutils-4.0.orig/src/du.c Sat Sep 19 18:09:23 1998 +++ fileutils-4.0/src/du.c Fri Oct 6 19:48:12 2000 @@ -36,6 +36,7 @@ -L Dereference all symbolic links. --exclude=PAT Exclude files that match PAT. -X FILE Exclude files that match patterns taken from FILE. + -C Count file lengths, not space occupied By [EMAIL PROTECTED], Torbjorn Granlund, and [EMAIL PROTECTED], David MacKenzie. @@ -138,6 +139,9 @@ /* If nonzero, dereference symlinks that are command line arguments. */ static int opt_dereference_arguments = 0; +/* If nonzero, count lengths not space occupied */ +static int opt_count_lengths = 0; + /* Show the total for each directory (and file if --all) that is at most MAX_DEPTH levels down from the root of the hierarchy. The root is at level 0, so `du --max-depth=0' is equivalent to `du -s'. */ @@ -147,6 +151,9 @@ if negative, the human-readable base. */ static int output_block_size; +/* Block size that we count in */ +static int input_block_size; + /* Accumulated path for file or directory being processed. */ static String *path; @@ -172,7 +179,7 @@ /* File name patterns to exclude. */ static struct exclude *exclude; -/* Grand total size of all args, in units of ST_NBLOCKSIZE-byte blocks. */ +/* Grand total size of all args, in units of input_block_size-byte blocks. */ static uintmax_t tot_size = 0; static struct option const long_options[] = @@ -194,6 +201,7 @@ {"separate-dirs", no_argument, NULL, 'S'}, {"summarize", no_argument, NULL, 's'}, {"total", no_argument, NULL, 'c'}, + {"length", no_argument, NULL, 'C'}, {"help", no_argument, &show_help, 1}, {"version", no_argument, &show_version, 1}, {NULL, 0, NULL, 0} @@ -229,6 +237,7 @@ -S, --separate-dirs do not include size of subdirectories\n\ -s, --summarize display only a total for each argument\n\ -x, --one-file-system skip directories on different filesystems\n\ + -C, --length count file lengths, not space occupied\n\ -X FILE, --exclude-from=FILE Exclude files that match any pattern in FILE.\n\ --exclude=PAT Exclude files that match PAT.\n\ --max-depth=N print the total for a directory (or file, with --all)\n\ @@ -267,7 +276,7 @@ human_block_size (getenv ("DU_BLOCK_SIZE"), 0, &output_block_size); - while ((c = getopt_long (argc, argv, "abchHklmsxDLSX:", long_options, NULL)) + while ((c = getopt_long (argc, argv, "abchHklmsxDLSX:C", long_options, NULL)) != -1) { long int tmp_long; @@ -342,6 +351,10 @@ error (1, errno, "%s", optarg); break; + case 'C': + opt_count_lengths = 1; + break; + case CHAR_MAX + 1: add_exclude (exclude, optarg); break; @@ -385,6 +398,8 @@ if (opt_summarize_only) max_depth = 0; + input_block_size = opt_count_lengths ? 1 : ST_NBLOCKSIZE; + /* Initialize the hash structure for inode numbers. */ hash_init (INITIAL_HASH_MODULE, INITIAL_ENTRY_TAB_SIZE); @@ -397,7 +412,7 @@ } /* Print N_BLOCKS followed by STRING on a line. NBLOCKS is the number of - ST_NBLOCKSIZE-byte blocks; convert it to OUTPUT_BLOCK_SIZE units before + input_block_size-byte blocks; convert it to OUTPUT_BLOCK_SIZE units before printing. If OUTPUT_BLOCK_SIZE is negative, use a human readable notation instead. */ @@ -406,7 +421,7 @@ { char buf[LONGEST_HUMAN_READABLE + 1]; printf ("%s\t%s\n", - human_readable (n_blocks, buf, ST_NBLOCKSIZE, output_block_size), + human_readable (n_blocks, buf, input_block_size, output_block_size), string); fflush (stdout); } @@ -499,7 +514,10 @@ && hash_insert (stat_buf.st_ino, stat_buf.st_dev)) return 0; /* Have counted this already. */ - size = ST_NBLOCKS (stat_buf); + if(opt_count_lengths) + size = stat_buf.st_size; + else + size = ST_NBLOCKS (stat_buf); tot_size += size; if (S_ISDIR (stat_buf.st_mode)) --- fileutils-4.0.orig/doc/fileutils.texi Sun Nov 8 16:12:07 1998 +++ fileutils-4.0/doc/fileutils.texi Fri Oct 6 19:55:37 2000 @@ -2878,6 +2878,14 @@ Skip directories that are on different filesystems from the one that the argument being processed is on. +@item -C +@itemx --length +@opindex -C +@opindex --length +@cindex counting file lengths in @code{du} +Count the length of files, rather than the space they occupy (which is +generally slightly larger due to the way filesystems work). + @itemx --exclude=@var{PAT} @opindex --exclude=@var{PAT} @cindex excluding files from @code{du} _______________________________________________ Bug-fileutils mailing list [EMAIL PROTECTED] http://mail.gnu.org/mailman/listinfo/bug-fileutils