Outils pour utilisateurs

Outils du site


issue154:tutoriel1

Ceci est une ancienne révision du document !


I have received four questions in this month’s Q&A and 2 last month regarding directory size and file size. I will also cover the “what is eating up all my space” etc. Rather than repeating myself over and over, I thought I would make a quick tutorial. Ubuntu has a nice little program called disk usage analyser (below).

This lets you drill-down into folders and see what is taking up so much space. However, there may come a time when you do not have the space to install anything more. There may even be a time where you have no internet access to install disk-usage-analyser. Fear not, you need the ‘du’ command. You may not like the terminal and that is fine, but sometimes you need to use it. The nifty thing about what I am going to show you is that it is fast. So what does the ‘manpage’ say? Well it is about as clear as rice pudding: “DESCRIPTION: Summarize disk usage of the set of FILEs, recursively for directories. Mandatory arguments to long options are mandatory for short options too.”

The amount of options is not overwhelming, but it does not really help you out either. When I give someone a helping hand, I often get a “huh?”, so I understand why we get so many of these questions. Let us start with the basics: If you are in the folder you want to know about, type: du -skh or du -smh Let’s dissect that. We (-s) summarize, (-k) kilobytes, (-m) megabytes, (-h) human readable

Sometimes, You want to see more than just what the current folder holds. Just remember – du can access only what your user can access, so you cannot see what is inside another user’s folder if you do not have permissions. Would you like to see each file in a folder? The you want: du-ah | less If you want it summed up to a grand total, use the -c flag. You may be looking for those huge files you put somewhere, then you use the -t flag. For example: du -h -t 500M -a /

The last thing I want to draw your attention to is the -d flag. You may not want to traverse every subfolder, but just want to check a subfolder’s subfolder. In that case: du -d1 or du -d2 -will do the job. Your homework is to see if you can use the: - -exclude flag. So now you have everything you need to make yourself a nice alias. How about you pipe a “ls” command of a folder through the “du” command? See where this is going? <insert eyebrow wiggle here>. Try to decipher the following command: sudo ls -1d */ | sudo xargs -I {} du {} -sh && sudo du -sh

Better yet, try it in a terminal. If you are stuck, email us on misc@fullcirclemagaine.org So: sudo ls -1d */ - Displays the top level folders (1 deep from the root) , we then use xargs to take that output and pipe it into sudo du -sh and the reason we use sudo is because we need permissions to size folders we do not have regular access to. Now if you use sed and awk, you can sort that by size too, but I would like to point out that you can use ncdu, which adds the ncurses version of a progress bar to make it stand out more. You can use ncdu on any folder with: ncdu /<foldername>

This is by far the easiest way to get folder sizes. Just be aware that this will not be available on legacy systems. But think about aliasing a long du command for use in situations where you need to make space and want to find that pesky ‘.iso’ file you copied into the opt folder by mistake. Very handy reference: https://www.rootusers.com/13-du-disk-usage-command-examples-in-linux/

issue154/tutoriel1.1583307082.txt.gz · Dernière modification : 2020/03/04 08:31 de d52fr