Score:-1

Remove all files in folder except files with certain sequence

af flag

I have a folder with a massive number of .dat files that follows a certain pattern (i.e., *_t_0.1000.dat, *_t_0.1001.dat .... , *_t_0.2000.dat). What I eventually want to do is to delete all files except files that ends with the sequence: *_t_0.1000.dat, *_t_0.1005.dat,*_t_0.1010.dat ... *_t_0.2000.dat. It is important to mention that the file ends with numbers that have 4 significant digits always. Can you help me with that?

Score:1
za flag

Try

ls "*_t_0.1??[12346789].dat"

to check, if the filter works, then

rm "*_t_0.1??[12346789].dat"

if so. Delete "*_t_0.2000.dat" manually, if the rule stops at 2000 but the files don't.

Else replace the 1 with [12] or ? too.

An alternative might be to use 4 commands like this:

 ls "xy_t_0."{1001..1096..5}".dat" 
 ls "xy_t_0."{1002..1097..5}".dat" 
 # you get it? 

Again, replace ls with rm, if the list is ok.

user844843 avatar
af flag
That worked! thanks a lot.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.