E
E
Eugene Wolf2019-11-06 23:55:00
linux
Eugene Wolf, 2019-11-06 23:55:00

How to write a command to find two files with different extensions?

Colleagues, good day!
Please help with the following question: there is a command to search for files in the N directory, for example: How to modify it so that the found PNG file is deleted only if in the same folder, next to this file, there will be a file with such same name but extension .JPG? Thank you!
find /tmp -type f -name "*.png" -exec rm -f {} \;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aves, 2019-11-07
@Wolfnsex

find /tmp -type f -name "*.png" -exec sh -c 'n={}; [ -f ${n%png}JPG ] && rm -fv $n' \;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question