Kategorie szkoleń | Egzaminy | Kontakt
  • 1
  • 1
  • 57

"Przypadkiem" utworzył się katalog z dużą ilością małych plików. Plików jest bardzo dużo - dziesiątki milionów. System plików to ext3.

Zawartość plików nie jest do niczego potrzebna - czy jest jakaś możliwość by efektywniej(szybciej/mniej obciążając system) niż rm -rf usunąć cały katalog?

Andrzej_Dopierała
  • Zapytał
  • @ Andrzej_Dopierała | 31.07.2016
    • lider
    • laureat
    • ekspert
    • 83
    • 65
    • 169

Odpowiedź (1)

  • 8

Przed opreacją usuwania plików warto by wyłączyć dziennik i zrobić remount noatime i nodirtime.

mount -o remount,rw,noatime,nodiratime /mountpoint


tune2fs -O^has_journal /dev/sdax1  LUB  
tune4fs -O ^has_journal /dev/sdax

W tym wypadku samo rm -fr będzie szybsze jednak nie tak szybkie jak by się chciało.

Można użyć rsync.

mkdir katolagbezzawartosci
rsync -a --delete katolagbezzawartosci/ yourdirectory/

 

Możesz wypróbować c++ powinien być wydajniejszy. :) 

 

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>

 

void delete_folder_tree(const char *dirname)
{
DIR *dir;
struct dirent *entry;
char path[PATH_MAX];

if (path == NULL) {
printf("Out of memory error\n");
return;
}
dir = opendir(dirname);
if (dir == NULL) {
printf("Error opendir()");
return;
}

while ((entry = readdir(dir)) != NULL) {
if (strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) {
snprintf(path, (size_t) PATH_MAX, "%s/%s", dirname, entry->d_name);
if (entry->d_type == DT_DIR) {
delete_folder_tree(path);
} else {
unlink(path);
}
}

}
closedir(dir);

rmdir(dirname);
printf("(not really) Deleting: %s\n", dirname);

return 1;
}


int main()
{
delete_folder_tree("/home/cg/root/onet/");
return 0;
}



 

Jacek_Zaleski
  • Odpowiedział
  • @ Jacek_Zaleski | 01.08.2016
    • 0
    • 0
    • 2