How do I produce sorted list of files in current directory over a certain size?
Hi all,
I have a need to produce a list of files in the current directory which exceed a given size (say, 500k). In addition, the list needs to be sorted by the size of the file from smallest to largest size and not list any file below the given size (again, say 500k). An example of the output I am looking for goes like this: LargeFile001 (501k) BigFile002 (503k) FileWav (800k) FileMP3 (22M) (SmallFile, which is 499k, would not show up on the report). I've tried using various combinations of the ls, find, du, and sort commands using the pipe, but I do not get the expected result. Instead, I get things like all files of all sizes (including those below the cutoff) listed in sorted order, or all files greater than the specified size but not in sorted order. I even managed to put together one combination of commands that caused the system to list the same thing over and over non-stop. Ideally, I can get this task done using a command line entry, as opposed to having to write out a script. Can someone here help me to solve this problem? Thanks, b. |
Re: sort
You have the right idea ... just put everything together with pipes ... and a little extra:
full ls of files larger than 500k sort these on the 5th field cut out everything up to the first "/" Code:
ls -l `find . -maxdepth 1 -size +500k` | sort -k 5,5 | cut -f 2 -d / > sort.txt |
* Find all user files larger than 5Mb:
Code:
find /home -size +5000000c -print Quote:
|
The ls command worked well for this mission, although eventually I had to remove the cut command because the boss wanted to see the details of each file listed. I didn't realize that one can pass the results of a command to another command via the use of backticks.
Thank you for your help! :) Cheers, b. |
All times are GMT -5. The time now is 11:04 AM. |