Even though Linux has developed so much in terms of GUI which has become comparable to the latest Aero theme from Microsoft’s stables (especially in KDE environment) the command line becomes an inevitable tool for performing advanced administrative tasks like setting user quotas, compiling from the source to name it a few. But unlike the command line in windows, Linux command line works differently. A good example is showing the sizes of directories while listing the contents. The “ls” command in Linux shows a list of files and directories in the present directory but doesn’t show the sizes of directories and the file sizes are shown in bytes which makes it difficult to read and understand. So the correct command for this purpose is “du“
Display sizes of all files and directories
Just entering the du command will show the entire list of files and directories in the current directory with their sizes in KB, the last line shows the size of the entire directory without any units. Not so useful isn’t it ? Lets move on to something more useful.
Display sizes in human readable format
So earlier when the sizes of the directories were displayed it was difficult to interpret whether the displayed size was in KB or MB and several digits were displayed for files of huge sizes which would’ve left you confused. A parameter -h will display sizes in KB, MB or GB according to the file size which makes it human readable.
Look at the screenshot below for du -h in action
Display the size in one line
In the previous examples you would’ve noted that the entire list of files and directories in the current location are displayed. What if you only need the size of the current directory you are in ? Use the -s parameter and a single line showing the size is displayed. This parameter can be combined with -h to display the size in human readable format.
Type du -sh to display the size in one line in human readable format
Display the size of the specified directory
Till now we have been seeing how to display the size of the present working directory, now we’ll see how to specify the particular directory for which the size should be displayed. The syntax is du [parameters] [path/to/directory]
The screenshot below shows the command du -sh /etc in action
You aren’t limited to only these options just type du –help to get a complete list of parameters for the du command.
Leave a Reply