2

I have a directory where I am writing lots of files but I know each of them fall under one of the 3 pre-determined memory sizes based on what I write. Any file I write may be either 300KB or 129.1MB or 251MB. Now if there is any packet error in the incoming data, the files that I write will not fall under one of these buckets. Since there will be so many files generated I will not be able to check the individual file size manually. Hence I need a way by which I can group all files by its size so that most of the files will fall under the three category mentioned above and I can easily find the files that are bad.

In short I want something like this: select file_names from folder and group by file_size. Is it possible?

Edit: It would be even better if anyone can give me a solution by which I can: select file_names from folder whose filesize not in [300KB,129.1MB,251MB]. Any ideas?

1 Answer 1

1

To sort files by size you can use ls command with -S option:

ls -lhS

For reverse order, use -r option:

ls -lhSr

I used also -l option to use a long listing format, and -h option to print sizes in human readable format (e.g., 300KB or 129.1MB or 251MB)

See man ls for more info.

4
  • This does what i asked but still I have to scroll a lot to find those that are bad. After asking the question I feel it would be more comfortable if I can do this:select file_names from folder whose file size is not in [300KB,129.1MB,251MB]. Is this possible?
    – Vivek V K
    Apr 3, 2014 at 17:28
  • 1
    @VivekVK You can try for example, if you are sure about those sizes: ls -lhS | grep -vE "300K|129.1M|251M" Apr 3, 2014 at 17:33
  • But why the 'h' option in 'ls' is ceiling 129.1M to 130M??.The command works perfect without it though.
    – Vivek V K
    Apr 3, 2014 at 17:41
  • 1
    @VivekVK -h - print sizes in human readable format. To see the difference use ls with and without this option. Apr 3, 2014 at 17:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .