0

I am using Debian 10 Buster and I am a Linux newby. It´s never too late..

I am collecting pictures in order to create a long-term time lapse video of a construction site across the street.

All of the pictures are in a directory inluding pictures taken Saturday and Sunday.

The filenames are formated like this:

YYYY-MM-DD_HHMM.jpg

example

2021-05-07_1012.jpg

Now i am trying to remove pictures that were created Saturdays and Sundays.

When executing below (from another thread here) I am able to list all files created Saturdays and Sundays:

find -type f -printf '%Ta\t%p\n' | egrep "^(Sat|Sun)" | cut -f 2-

The question is: How do I modify this line into a delete statement to remove the files?

Another option could be (i store the files on a nas) the exclude the files when copying them into my working directory.

I use rsync to copy the files over.

Thanks in advance.

Panki
  • 6,664
  • Unfortunately i do not think this answers my question or you need to help me understand it.

    As far as i can see, this generically removes files based on patterns. Here there is no pattern as such, I would need to extact the weekdays from the file properties and then delete Sat and Sun only.

    – prankprompidelio Aug 18 '21 at 09:30
  • The relevant part for you is piping to xargs, the find command in that question does not matter. – Panki Aug 18 '21 at 10:49

1 Answers1

1

Appending xargs rm to the command, so that we have:

find -type f -printf '%Ta\t%p\n' | egrep "^(Sat|Sun)" | cut -f 2- | xargs rm

Will delete any of the files that match your search results. You can also use rm -v to view which files were deleted.

xargs reads items from the standard input, and as you said in a comment, it can be used with patterns. Our pattern here however is defined with find, printf, egrep and cut.

After running your command to locate the files, the relative paths are printed, but when we use xargs rm those paths are given to rm via xargs, and subsequently deleted.

brxken
  • 63