I am trying to display the top 20 largest files in a specific directory. I want to include all sub directories but not the actual directories themselves. (I only want files.) I have been trying to find a way to do this and all the solutions I have found online do not work with the version on Unix I am using.
I have this so far:
find /dir -type f -exec ls -al {} \; | sort -nr | head -n 20
du -a -g /dir/ | sort -n -r | head -n 20
The fist gives me a list as follows:
file1.txt
file1.txt
file1.txt
file2.txt
And so on. The second command gives me the following:
500 \path\
250 \path\to\
100 \path\to\directory\
And so on. The result I am looking for is:
500 \path\file1.txt
250 \path\to\file2.txt
100 \path\to\directory\file3.txt
And so on. I have tried the solutions from the following questions:
- Finding largest file recursively
- https://stackoverflow.com/questions/12522269/how-to-find-the-largest-file-in-a-directory-and-its-subdirectories
I have also tried to follow this tutorial: