shell stuffs

using the command line

du and the biggest directory

du is a nice tool which can show you the total space occupied by all the files of a directory:

$ du -sm /bin /lib*
13	/bin
952	/lib
6	/lib32
1	/lib64

In that command, I asked the size of /bin and of all /lib* directory (flag -s) and the result is in megabytes (flag -m). On my computer, /bin files use 13 Mb. With sort and head, we can find the directories which occupies the most disk space:

$ du -sm /usr/local/* | sort -rn | head -3
4408	/usr/local/tools
928		/usr/local/java
141		/usr/local/bin

If I need to free space on my disk, I will clean /usr/local/tools in first, it occupies 4 Go. And to know more, I now do:

cd /usr/local/tools && du -sm * | sort -rn | head -3
1699	OracleDeveloperStudio12.6-solaris-x86-bin
883		idea-IC-173.3942.27
721		smalltalk-X

I can win more than 1 Gb by removing Oracle Developer Studio 12.6 which I do not use since a long time.

several commands and error handling

The last simple in du and the biggest directory show the use of && between the two commands which could be written like that:

cd /usr/local/tools; du -sm * | sort -rn | head -3
...

We will get the same result than before (unless I have deleted Oracle Developper Studio). If I did