1

How can I list the largest 3 directories/files which are directly (not recursive) in my home directory using a command?

  • 1
    you can use du -a . | sort -nr | head to list top 10 files or directories based upon size. – Tarun Jan 28 '14 at 8:04
  • Do you want to recurse into subdirectories of your Home, or do you want the largest 3 folders directly in your home folder? This is not clear in your question. – kiri Jan 28 '14 at 8:22
  • Thats is my fault i want largest 3 directories directly found in home folder – Maythux Jan 28 '14 at 8:24
  • This doesn't directly answer your question, but ncdu is a pretty amazing tool to use if you want to find out what's using up your disk space. – nyuszika7h Mar 15 '15 at 0:09
5

You can use these commands:

shopt -s dotglob
du -hs  "$HOME"/* | sort -hr | head -n3

Example output:

16G     /home/me/.local
455M    /home/me/.minecraft
417M    /home/me/.cache
  • It goes recursive so that in my case i obtain the same size twice one for the file and one for the directory contains the file. – Maythux Jan 28 '14 at 8:16
  • 13G /home/maythux/VirtualBox VMs/server/server.vdi 13G /home/maythux/VirtualBox VMs/server – Maythux Jan 28 '14 at 8:16
  • @maythux To fix that, just remove the -a option. Also, can you raise your queries with my answer in comments instead of in your own answer? – kiri Jan 28 '14 at 8:17
  • ok i do it but still taking much time i think that the command i tried is faster.. try yourself – Maythux Jan 28 '14 at 8:18
  • 1
    I don't know why this answer got a thumb down. This is working fine and also returns the size in Human readable format with G, M or K. – Saurav Kumar Jan 28 '14 at 8:50
3

I found this command which is so fast with respect to other answers

du -sm * | sort -nr | head -3
  • Yes your answer is fast, but hard to guess whether you size is in bytes, kb, mb or gb.. :D Although +1 for fast answer.. – Saurav Kumar Jan 28 '14 at 8:52
  • How is this "faster"? And you don't meet your own request - searching in your home directory. – guntbert Feb 22 '14 at 16:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.