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 

Comments

Popular posts from this blog

Perm Root HTC Desire Gingerbread 2.3.3

Increase Free Space On HTC Desire Android Phones

Logging Handler With Buffering And Uses Amazon SES For Python