Как удалить много файлов на сервере
Иногда бывает такое, что множество файлов скапливаются на сервере со временем.
ubuntu@ftp-client01:~$ ftp ftp> open ftp-server01 Connected to ftp-server01. 220 Welcome to the Web FTP service. Name (ftp-server01:ubuntu): admin 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> ftp> ls 200 PORT command successful. Consider using PASV. 150 Here comes the directory listing. drwxrwx---2 ftpftp 3878912 Sep 07 00:07 Web_DC1_Log_Dir drwxrwx---2 ftpftp 36864 Sep 06 07:37 testdatabase 226 Directory send OK.
Пока все хорошо, я вошел в систему и могу перечислить каталоги. Кажется, есть также папка тестовой базы данных.
Сначала проверим содержимое, чтобы убедиться, что я правильном направлении.
ftp> cd Web_DC1_Log_Dir 250 Directory successfully changed. ftp> dir 200 PORT command successful. Consider using PASV. 150 Here comes the directory listing. -rw-r--r-- 1 ftp ftp 3778547 Jun 15 05:16 webserver.local01-2018-06-15-05_003.log.gz -rw-r--r-- 1 ftp ftp 4002151 Jun 15 05:21 webserver.local01-2018-06-15-05_004.log.gz -rw-r--r-- 1 ftp ftp 4139598 Jun 15 05:26 webserver.local01-2018-06-15-05_005.log.gz -rw-r--r-- 1 ftp ftp 3936480 Jun 15 05:31 webserver.local01-2018-06-15-05_006.log.gz -rw-r--r-- 1 ftp ftp 3772733 Jun 15 05:36 webserver.local01-2018-06-15-05_007.log.gz -rw-r--r-- 1 ftp ftp 3763328 Jun 15 05:41 webserver.local01-2018-06-15-05_008.log.gz -rw-r--r-- 1 ftp ftp 3725765 Jun 15 05:46 webserver.local01-2018-06-15-05_009.log.gz -rw-r--r-- 1 ftp ftp 3597685 Jun 15 05:51 webserver.local01-2018-06-15-05_010.log.gz 226 Directory send OK. ftp> cd .. 250 Directory successfully changed. ftp> cd testdatabase 250 Directory successfully changed. ftp> dir 200 PORT command successful. Consider using PASV. 150 Here comes the directory listing. -rw-r--r-- 1 ftp ftp 1394829 Apr 14 02:00 Web_Reporter_140.log.gz.done -rw-r--r-- 1 ftp ftp 1394711 Apr 15 02:00 Web_Reporter_150.log.gz.done -rw-r--r-- 1 ftp ftp 1386116 Apr 16 02:00 Web_Reporter_160.log.gz.done -rw-r--r-- 1 ftp ftp 1314330 Apr 17 02:00 Web_Reporter_170.log.gz.done -rw-r--r-- 1 ftp ftp 1292357 Apr 18 02:00 Web_Reporter_180.log.gz.done -rw-r--r-- 1 ftp ftp 1289469 Apr 19 02:00 Web_Reporter_190.log.gz.done 226 Directory send OK. ftp> cd .. 250 Directory successfully changed. ftp> dir 200 PORT command successful. Consider using PASV. 150 Here comes the directory listing. drwxrwx--- 2 ftp ftp 3878912 Sep 07 00:12 Web_DC1_Log_Dir drwxrwx--- 2 ftp ftp 36864 Sep 06 07:37 testdatabase 226 Directory send OK.
Похоже, все хорошо.
Давайте попробуем cli-kungfu, прежде чем попробовать его в главном каталоге.
ftp> ? Commands may be abbreviated.Commands are: !debugmdirqcsend $dirmgetsendportsite accountdisconnectmkdirputsize appendexitmlspwdstatus asciiformmodequitstruct bellgetmodtimequotesystem binaryglobmputrecvsunique byehashnewerregettenex casehelpnmaprstatustick cdidlenlistrhelptrace cdupimagentransrenametype chmodlcdopenresetuser closelspromptrestartumask crmacdefpassivermdirverbose deletemdeleteproxyrunique?
mdelete, безусловно отличный вариант, поскольку вы можете удалить множество файлов.
Давайте попробуем это.
Попробуем сделать что-то еще, например rm -r или rmdir -r, для рекурсивного удаления.
ftp> ftp> rm -r testdatabase 550 Remove directory operation failed. ftp> rm -r testdatabase/* 550 Remove directory operation failed. ftp> rmdir -r testdatabase/* 550 Remove directory operation failed. ftp> dir 200 PORT command successful. Consider using PASV. 150 Here comes the directory listing. drwxrwx---2 ftpftp 3878912 Sep 07 00:12 Web_DC1_Log_Dir drwxrwx---2 ftpftp 36864 Sep 07 00:14 testdatabase 226 Directory send OK. ftp> exit 221 Goodbye.
Хорошо, это был провал!
Я обыскал информацию о FTP и информацию о том, как удалить непустую папку или массовое удаление файлов из CLI.
Каждый использует некоторый GUI-клиент, который позволяет это.
Наконец я нашел способ.
По-видимому, вы можете использовать флаг -i для отключения интерактивности, поэтому FTP не будет запрашивать каждую строку при использовании mdelete.
Надеюсь, что это сработает:
ubuntu@ftp-client01:~$ ftp -i ftp> open ftp-server01 Connected to ftp-server01. 220 Welcome to the Reporter FTP service. Name (ftp-server01:ubuntu): admin 331 Please specify the password. Password: 230 Login successful. Remote system type is UNIX. Using binary mode to transfer files. ftp> ftp> ftp> ls 200 PORT command successful. Consider using PASV. 150 Here comes the directory listing. drwxrwx---2 ftpftp 3878912 Sep 07 00:12 Web_DC1_Log_Dir drwxrwx---2 ftpftp 36864 Sep 07 00:14 testdatabase 226 Directory send OK. ftp> mdelete -r testdatabase/* 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful.
Это работает! Теперь попробуйте ту же команду в большой папке:
ftp> mdelete -r Web_DC1_Log_Dir/* 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. 250 Delete operation successful. ftp> cd Web_DC1_Log_Dir 250 Directory successfully changed. ftp> dir 200 PORT command successful. Consider using PASV. 150 Here comes the directory listing. 226 Directory send OK. ftp> ls 200 PORT command successful. Consider using PASV. 150 Here comes the directory listing. 226 Directory send OK.
Похоже, что каталог теперь пуст и его можно удалить.
ftp> cd .. 250 Directory successfully changed. ftp> rmdir Web_DC1_Log_Dir 250 Remove directory operation successful. ftp> ftp> rmdir testdatabase 250 Remove directory operation successful. ftp> dir 200 PORT command successful. Consider using PASV. 150 Here comes the directory listing. 226 Directory send OK. ftp> ftp> ls 200 PORT command successful. Consider using PASV. 150 Here comes the directory listing. 226 Directory send OK. ftp> exit 221 Goodbye.
Вот и вся магия
0 Комментарии