Q dir show folder size code#
Step 2: Mount drive by running this code in a cell: from lab import drive Step 1: Visit Google Colab and create a new python 3 notebook. Usefull to know exactly which of the subdir of /some/path are big.One approach to this is using Google Colab.
To know the sum of content of directories + subdirs:ĭu /some/path # will show for each directory : the sum of its content (including subdirs), and shows that for every directory at and underneath /some/pathĭu -s /some/path # will show only 1 level, ie just the total for /some/pathĭu -S /some/path # show the content of each dir, not including their subdirs. See man ls to see how they are identified as well.) for pipes, and other files types : each time the field usually associated with size may or may not be a size (ex: for block-devices (ex: /dev/hd* files ) it doesn't show any size but instead shows their major, minor pair of information.If you ever put MANY files in some directory, this will go up (and most likely will stay up afterwards, unless you recreate the directory itself). This is why you see 4096 for most of them : usually they don't have many files inside them so it fits all into 1 inode, which is usually 4096 bytes per default. for directories: the size of an inode (if the content of the directory entries fits into one) or multiple inodes (if there was a need for multiple inodes to describe the list of that directory's entries).(ex: the symlink /dev/fd -> /proc/self/fd : has a destination path exactly 13 caracters long ( / p r o c / s e l f / f d ), so ls -l will display "13" in the 5th column, instead of the size of the pointed-at file.) for symlinks (symbolic links, ln -s source dest) : the length of the symlink name (as this the content of the symlink file).for regular files : it shows their actual size.Ls shows the size of the regular files (or, in case of directories, the size of its inodes, not just their content, as it has no quick way to determine that, whereas for regular files the size is known and thus can be displayed exactly and quickly).Īctually that field differs depending on what the file represents :
Output of du -sh ~/Desktop command 80M /home/rahul/Desktop Is there any way to do it?Ĥ.0K drwxrwxr-x 2 rahul rahul 4.0K Mar 10 12:24 binĤ.0K drwxrwxr-x 8 rahul rahul 4.0K May 8 14:51 boxfitv2Ĥ.0K -rw-rw-r- 1 rahul rahul 3.2K May 13 13:28 c.cħ.7M -rw-rw-r- 1 rahul rahul 7.7M May 15 15:35 Costa_ODE.pdfĤ.0K drwxrwxrwx 2 rahul rahul 4.0K Jan 30 11:50 dao2Ġ -rw-rw-r- 1 rahul rahul 0 May 13 20:37 default.txtĤ.0K drwxrwxr-x 2 rahul rahul 4.0K deja-dupĤ.0K drwxr-xr-x 6 rahul rahul 4.0K May 16 17:11 DesktopĤ.0K drwxr-xr-x 3 rahul rahul 4.0K May 15 10:53 DocumentsĤ.0K drwxr-xr-x 5 rahul rahul 4.0K May 8 14:09 Downloadsġ2K -rw-r-r- 1 rahul rahul 8.8K sktop In short, the command ls -lS is not calculating the size of the contents of Desktop and other sub-directories. But when I tried to see the details of Desktop, this is what I got. But I want you to focus on sub-directories, for example Desktop. rw-r-r- 1 rahul rahul 8980 sktopĭrwxrwxr-x 2 rahul rahul 4096 Mar 10 12:24 binĭrwxrwxr-x 8 rahul rahul 4096 May 8 14:51 boxfitv2ĭrwxrwxrwx 2 rahul rahul 4096 Jan 30 11:50 dao2ĭrwxr-xr-x 6 rahul rahul 4096 May 16 02:12 Desktopĭrwxr-xr-x 3 rahul rahul 4096 May 15 10:53 Documentsĭrwxr-xr-x 5 rahul rahul 4096 May 8 14:09 DownloadsĪnd its a pretty big list. This is what I got after running this command total 10148 This command is supposed to list down the contents of a directory by size. I used ls -lS command in my home directory.