I want to do something like this
du -a | sort -rn | head
But I want to extract files only, ignoring directories.
To be clear, I want to traverse through all sub-directories but I don't want to find directory sizes. Just files sizes.
UPDATE
I also want to return the full path of the files
This should work:
Taken from http://unix-linux.itags.org/q_unix-linux-programming_84920.html
One way to find the largest file in a directory:
I just want to add my solution although it's not as complete as the one by @Michael Plotke
UPDATE 1
I've now had to use this script on BSD unix (which I did not originally intended to do) and found Michael's solution doesn't work.
By incorporating @steve's solution into mine, this solution is more usable on BSD systems:
UPDATE 2
Further refinement. Resolves issues with unusual filenames (eg. spaces)
Note: I found this solution to be significantly faster on WSL (windows subsystem Linux) than the accepted solution.
In a directory with about 1000 files, this solution takes seconds whereas the accepted answer took tens of minutes.