find -exec rm для нескольких файлов

#include<stdio.h>
#include <signal.h>
 void signalHandler(int);
int main()
{
    struct sigaction sa;
    sa.sa_flags = 0;
    // Setup the signal handler
    sa.sa_handler = signalHandler;
    // Block every signal during the handler
    sigfillset(&sa.sa_mask);  
    if (sigaction(SIGINT, &sa, NULL) == -1) {
    printf("Error: cannot handle SIGINT\n"); 
}

    while(1)
    {
        printf("Start to ping google.com");
        system("ping www.google.com -c 1");
        printf("Stop to ping google.com\n");
        sleep(1);
    }

}

void signalHandler(int signal)
{
    printf("signalHandler: signal = %d\n", signal); 
}
1
03.12.2016, 03:43
2 ответа

Другой вариант:

 WARNING: it is possible that due to funny characters in directory names it is possible that unintended files might be deleted.

 find ./ -type f \( -name fileA -o -name fileB \) -print | xargs rm -f

Или, если возможно, поймать эти файлы с забавными персонажами:

 NOTE: On some systems -print0 and -0 options are not available.  But this would be the preferred and safer method)

 find ./ -type f \( -name fileA -o -name fileB \) -print0 | xargs -0 rm -f
2
27.01.2020, 23:13

-o также применяется к действию, поэтому вам нужно сгруппировать вещи:

find ./ -type f \( -name fileA -o -name fileB \) -exec rm {} \; 

Кстати, ваша реализация find может также поддерживать -delete :

find ./ -type f \( -name fileA -o -name fileB \) -delete 
7
27.01.2020, 23:13

Теги

Похожие вопросы