Sort Files According To Their Size

With few basic commands in Linux box, we can generate a report of files according to ascending or descending order of their size.

Let's start by displaying all the files from a folder:
find ~/testFolder -type -f 
To get their size lets pass each file to du command:
find ~/testFolder -type -f -exec du -s {} \;
Now lets sort them according to their size in numeric order, taking first column as file size and in reverse order:
find ~/testFolder -type -f -exec du -s {} \; | sort -k1nr
Let's save the output to a file size.txt:
find ~/testFolder -type -f -exec du -s {} \; | sort -k1nr > ~/size.txt 


Popular posts from this blog

Adobe Stand Alone Flash Player for Linux

[Solved] invalid partition table on /dev/sda -- wrong signature 0.

Essential adb Command Examples