1

I want to find all directories (recursively) which contain .cue files, execute a command in that directory, then delete all files in that directory with the same prefix as the .cue file.

find . -name '*.cue' \( -execdir myotherscript.sh \; -execdir [rm ${}%.cue.*] \; \);

Obviously with the bit in brackets [rm...] not working.

For the deletion bit, if the directory contains a file like marley-birds.cue, I want to delete all files of the type marley-birds.* (including the .cue file itself).

  • 1
    Each directory will have only one .cue file. And the script just needs to run once per directory. – emacsomancer Oct 30 '16 at 22:30
  • 3
    Your 2nd execdir should be -execdir sh -c 'printf %s\\n "${0%.cue}"*' {} \; ... replace printf %s\\n with rm if you're happy with the result... I don't quite get the point of grouping the two execdirs. Why are you doing that ? – don_crissti Oct 30 '16 at 22:38
  • I suppose I don't really need to group them. – emacsomancer Oct 30 '16 at 22:49
  • @don_crissti: Worked perfectly. (I actually ended up just making 2 scripts and running each once - to make sure that the first executed correctly before removing files.) – emacsomancer Oct 30 '16 at 23:03
  • 1
    the 2nd execdir will never run if the 1st fails - just so you know; it's all in the manual; anyway, you could always post an answer and explain what you did. – don_crissti Oct 30 '16 at 23:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.