1

My assignment is: Find files (in a specific directory that is given) , show only the ones above 100 megabytes, sort them by size, print them in ls -lh format.

This is what I execute:

find /home/it21366 -size +10M | sort -h | ls -lh

This is what I get

-rwxr-xr-x+ 1 it21366 unixusers  12K Απρ  28  2014 a.out
-rwxr-xr-x+ 1 it21366 unixusers  471 Νοέ  29 10:51 askisi.sh
-rw-r--r--+ 1 it21366 unixusers 3,0K Απρ  28  2014 code.c
-rw-r--r--+ 1 it21366 unixusers 3,0K Απρ  28  2014 code.c~
-rw-r--r--+ 1 it21366 unixusers 6,2K Απρ  28  2014 CODE.txt
-rw-------+ 1 it21366 unixusers 2,0M Απρ  28  2014 core
-rwxr-xr-x+ 1 it21366 unixusers   66 Δεκ   6 14:39 it21366_ex_1_1
-rwxr-xr-x+ 1 it21366 unixusers  190 Δεκ   6 14:35 it21366_ex_1_4.sh
-rwxr-xr-x+ 1 it21366 unixusers  190 Δεκ   6 14:27 it21366_ex_1_4.sh~
-rwxr-xr-x+ 1 it21366 unixusers  546 Δεκ   5 17:46 it21366_ex_1_5
-rw-r--r--+ 1 it21366 unixusers 509K Οκτ  23  2014 java01.pdf
-rw-r--r--+ 1 it21366 unixusers 506K Οκτ  23  2014 java02.pdf
-rw-r--r--+ 1 it21366 unixusers 249K Οκτ  11 10:03 lab01_2018-19.pdf
-rw-r--r--+ 1 it21366 unixusers 1,2K Οκτ  24 16:27 MyClock.java
-rw-r--r--+ 1 it21366 unixusers 1,3K Οκτ  30  2013 starthere.desktop
-rw-r--r--+ 1 it21366 unixusers    3 Οκτ  24 12:45 test
-rw-r--r--+ 1 it21366 unixusers   12 Οκτ  24 12:45 TK.txt
-rw-r--r--+ 1 it21366 unixusers  14K Μάι  30  2018 Untitled 1.odt

I can't imagine why LS seems to ignore the other methods, and simply shows the contents of the files unsorted and unfiltered.

Rui F Ribeiro
  • 56,709
  • 26
  • 150
  • 232

2 Answers2

3

use xargs:

find /home/it21366 -size +10M | xargs ls -lhsSr 
Ipor Sircer
  • 14,546
  • 1
  • 27
  • 39
1

Another option, if the number of files is limited enough to fit in one (long) call to ls, would be to use find to find the large files and ls -S to do the sorting:

find /home/it21366 -type f -size +10M -exec ls -lS {} + 2>/dev/null

The -exec ... {} + tells find to replace the "found" files into the call to ls, fitting as many as it can. If there are too many files, you'll get multiple calls to ls and thus un-sorted results (they'll be sorted in groups). I also added -type f to restrict the matches to regular files.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255