1

The other day I ran bleachbit on my system. I had enabled wipe disk space option in it. It took several hours and my disk space filled up completely (100GB or so). After waiting forever, I decided to terminate the program and delete the files manually.

Now the problem: I'm not able to delete the files or the directory. I cannot do an ls within the directory. I tried rsync -a --delete, wipe, rm, different combos of find & rm, etc

I followed the instructions here and noticed the "Directory Index Full!" error in my logs as well. rm on a directory with millions of files

I noticed that the stat command returned an unusually large directory size of more than a GB. Usually it's just 4096 or something around tens of thousands.

nameh@labs ~ % stat kGcdTIJ1H1                                                                            
  File: ‘kGcdTIJ1H1’
  Size: 1065287680  Blocks: 2080744    IO Block: 4096   directory
Device: 24h/36d Inode: 9969665     Links: 2
Access: (0777/drwxrwxrwx)  Uid: ( 1000/  nameh)   Gid: ( 1000/  nameh)
Access: 2014-10-31 07:43:08.848104623 +0530
Modify: 2014-10-31 07:43:19.727719839 +0530
Change: 2014-10-31 07:43:19.727719839 +0530
 Birth: -

The "ONLY" command that so far seems to be able to delete files within this dir is the srm command (secure deletion toolkit by THC). All other commands do not work. srm has been running for 20 hours now and has freed up around 1.1 GB so far. It's running with the least secure mode.

sudo srm -v -rfll kGcdTIJ1H1

Ideas?

edit: My question is "how do I delete the directory quickly?". Like in a few hours or so without having to spend several days to delete the files. rm -rf does nothing.

5
  • 2
    What is your question? Oct 31, 2014 at 2:28
  • 1
    unmount the disk and then format it. Huge number of files are a big problem with some filesystem types. Did you run out of inodes or actual disk space?? You can control the number of files allowed on the reformatted disk during format. Oct 31, 2014 at 2:46
  • Michael, sorry about the ambiguity. So my question is 'how do I delete the directory in shorter time?' Oct 31, 2014 at 4:38
  • Something i faced before. hope this will be useful. unix.stackexchange.com/questions/96935/… Oct 31, 2014 at 10:09
  • MadHatter, pradeepchhetri, I checked both the links and tried all the options. When I run any of those, there's no output, the program does not exit, and they just keep running for hours and when I do 'df -k', I don't see any reduction in disk space usage. srm is the only tool that works but it's way too slow. It's been running for 70 hours now and has deleted 4GB so far. When srm is running, if I open another terminal and do anything, even ls, srm freezes. Nov 1, 2014 at 15:27

3 Answers 3

2

I have had similar issue where one of the partition was filled with millions of files and hence consumed all availbe inodes then even though the file system has almost 20GB free space I was not able to create any file on that because inodes were exhaused.

So I ran the find command that delted 1.4 millons files It took quite a while though becaue with find and exec combo find will pass each file to exec functoin which in turn runs the rm command on file

cd /to/directory find . -type f -exec rm {} \;

OR

You may want to try xargs

find . -type f |xargs rm

Both commands worked for me

hope it helps.

1
  • This option suddenly works now. But it takes a really long time to delete even a couple of blocks. I am guessing this is because of the filesystem btree rearrangement. Nov 2, 2014 at 2:02
2

you could use this perl trick:

perl -e 'chdir "/path/to/dir" or die; opendir D, "."; while ($n = readdir D) { unlink $n }'

what this does is, first goes to the directory, open it, and delete (unlink) all the files in it without getting the list of all files first (that is probably were rm is choking).

The trick is not mine, but Randal L. Schwartz's: http://blogs.perl.org/users/randal_l_schwartz/2011/03/perl-to-the-rescue-case-study-of-deleting-a-large-directory.html

2
  • Aha, this seems to work better than srm. I have recovered 5GBs over night. It's also way faster. Nov 2, 2014 at 1:52
  • 1
    A rare occassion when the last answer of a duplicate question solved the issue we had been struggling with for over two days +1 Thanks!
    – skv
    Apr 12, 2017 at 17:59
1

you can try the following

find . -type d -print -delete #drop the -print not to see what you delete, I find this is the fatest

find . -type f -exec rm {} \; #slower that above

find . -mtime +29 -print | xargs ls -d

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