root@dwarf /var/spool/clientmqueue # rm spam-* Root @ карлика / VAR / котушка / clientmqueue # RM-спам *
/bin/rm: Argument list too long. / BIN / RM: список аргументів занадто довгий.
Ever seen this error in Linux when you have too many files in a directory and you are unable to delete them with a simple rm -rf * ? Коли-небудь бачили цю помилку в Linux, коли у вас дуже багато файлів в каталозі і ви не зможете видалити їх з простими РМ-РФ *? I have run into this problem a number of times. Я зіткнулася з цією проблемою кілька разів. After doing a bit of research online I came across a neat solution to work around this issue. Зробивши кілька досліджень, в мережі я натрапив на акуратну роботу щодо вирішення цієї проблеми.
find . знайти. -name 'spam-*' | xargs rm спаму ім'я '-*' | xargs RM
In the above instance the command will forcefully delete all files in the current directory that begin with spam- . У наведеній вище команді Наприклад, будуть обов'язково видаліть всі файли в поточному каталозі, що починаються зі спамом. You can replace the spam-* with anything you like. Ви можете замінити спаму * з чим завгодно. You can also replace it with just a * if you want to remove all files in the folder. Ви також можете замінити його просто * Якщо ви хочете видалити всі файли в папці.
find . знайти. -name '*' | xargs rm -Name '*' | xargs RM
We have covered the Ми пройшли Linux find Linux знайти command in great detail earlier. Команда дуже докладно раніше. Xargs Xargs is Linux command that makes passing a number of arguments to a command easier. Linux є команда, яка робить передачу ряду аргументів в команді легше.























{ 3 comments… read them below or (3 Коментарі ... читати їх нижче або add one Додати одну } )
Safe variant for filenames with spaces, new lines and other whitespace characters: Безпечний варіант для файлів з пробілами, нові залізничні лінії та інші пробільні символи:
find . знайти. -name '*' -print0 | xargs -o rm -* '-Print0 назвою' | xargs-O RM
Good catch using the print0 option, that's an important one. Хороший улов допомогою print0 варіанту, це важливо.
Most find commands do not require the “-name” predicate. Більшість знайти команди не вимагають "ім'я" предикат. What's usually more important is to make sure you're deleting *files* and not something else you might not have intended. Що зазвичай більш важлива, щоб переконатися, що ви видаляєте файли * *, а не щось ще ви, можливо, не передбачалося. For this use “-type f” inplace of the “-name” option…. Для цього скористайтесь типу "F" Inplace з "ім'я-опції" ....
find . знайти. -type f -print0 | xargs -0 /bin/rm типу F-print0 | xargs -0 / BIN / RM
A) Use the full path to the 'rm' command so your aliases don't muck with things. А) використовувати повний шлях до "RM команду" так що ваші псевдоніми НЕ гидотою з речами.
B) Check your xargs command, you can sometimes, if needed, tell it to use one “result” at a time, such as (if you didn't use print0 but regular print) “-l1″ Б) Перевірте вашу команду xargs, іноді можна, при необхідності, повідомити йому використовувати одну "Результат" у той час, як (якщо ви не використовували, але регулярно print0 друк) "-L1"
find . знайти. -type f -exec rm {} \; типу F-Exec RM () \;
Leave a Comment Залишити коментар