1

Why do I have capacity in an empty folder?

I found a strange thing while I was developing after seeing the company's old project.

It was strange that the folder had a capacity of 36M, so I entered the folder, but there were no files.

I didn't understand what this was like.

So I created a folder to check the default capacity of the empty folder, and the default capacity was 4.0K.

Please tell me why the folder occupies 36M of capacity when it is an empty folder and no files exist

Below is the console log, and the name of the strange folder is logani. The newly created folder is testDirectory.

vnoc@AI-API01:~/project/src$ du -sh *
4.0K    app.js
28K     bin
32K     config
364K    control
32K     databases
4.0K    deploy.sh
4.0K    install.sh
36M     logani
27M     logs
16K     public
84K     routes
4.0K    scaleup.sh
4.0K    script
4.0K    start.sh
4.0K    stop.sh
24K     system
32K     test
20K     util
vnoc@AI-API01:~/project/src$ ls -la
total 36628
drwxrwxr-x 14 vnoc vnoc     4096 Apr 26 14:27 .
drwxrwxr-x  5 vnoc vnoc     4096 Mar 28 08:07 ..
-rw-rw-r--  1 vnoc vnoc     1710 Apr 26 14:26 app.js
drwxrwxr-x  3 vnoc vnoc     4096 Mar 11 15:05 bin
drwxrwxr-x  3 vnoc vnoc     4096 Apr 22 09:35 config
drwxrwxr-x  4 vnoc vnoc     4096 Aug  3  2021 control
drwxrwxr-x  3 vnoc vnoc     4096 Nov 18 16:45 databases
-rw-rw-r--  1 vnoc vnoc      155 Sep 21  2020 deploy.sh
-rw-rw-r--  1 vnoc vnoc      119 Sep 21  2020 install.sh
drwxrwxr-x  2 vnoc vnoc 37408768 Apr 27 09:32 logani
drwxrwxr-x  4 vnoc vnoc    20480 Apr 26 09:29 logs
drwxrwxr-x  3 vnoc vnoc     4096 Jan 24 16:11 public
drwxrwxr-x  4 vnoc vnoc     4096 Apr 27 07:58 routes
-rwxr-x---  1 vnoc vnoc       89 Nov  9  2020 scaleup.sh
drwxrwxr-x  2 vnoc vnoc     4096 Jan 14 18:00 script
-rwxr-x---  1 vnoc vnoc      708 Sep 22  2020 start.sh
-rwxr-x---  1 vnoc vnoc      217 Nov  9  2020 stop.sh
drwxrwxr-x  2 vnoc vnoc     4096 Apr 26 15:03 system
drwxrwxr-x  2 vnoc vnoc     4096 Mar 10  2021 test
drwxrwxr-x  2 vnoc vnoc     4096 Apr 27  09:55 testDirectory
drwxrwxr-x  2 vnoc vnoc     4096 Apr 25 15:33 util
vnoc@AI-API01:~/project/src$ cd logani
vnoc@AI-API01:~/project/src/logani$ ls -la
total 36536
drwxrwxr-x  2 vnoc vnoc 37408768 Apr 27 09:32 .
drwxrwxr-x 14 vnoc vnoc     4096 Apr 26 14:27 ..
vnoc@AI-API01:~/project/src/logani$ du -sh *
du: cannot access '*': No such file or directory
vnoc@AI-API01:~/project/src/logani$ 
1

1 Answer 1

2

Directories expand in size to hold the number of files inside it. But when you delete files they don't shrink.

So...

bash-4.2$ mkdir XXX
bash-4.2$ cd XXX
bash-4.2$ ls -ld .
drwxr-xr-x 43 sweh sweh 4096 Apr 26 22:32 .
bash-4.2$ for a in {1..10000}; do touch $a; done
bash-4.2$ ls -ld .
drwxr-xr-x 2 sweh sweh 155648 Apr 26 22:31 .
bash-4.2$ rm *
bash-4.2$ ls -ld .
drwxr-xr-x 2 sweh sweh 155648 Apr 26 22:32 .
2
  • Is capacity wasted when files inside are deleted after the directory size has been expanded? May 19, 2022 at 23:06
  • @JongSunPark Yes, and whether or not the directory is truncated when directory entries are removed depends on the type of filesystem in use.
    – Kusalananda
    Aug 11, 2022 at 10:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .