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:
Let's start by displaying all the files from a folder:
find ~/testFolder -type -fTo 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 -k1nrLet's save the output to a file size.txt:
find ~/testFolder -type -f -exec du -s {} \; | sort -k1nr > ~/size.txt
Comments
Post a Comment
Comments are moderated. No spam please.