I have such a problem, I'm trying to output a list of movies without the names of directories in the file, but I have a bug, the argument is not found in the -exeс, below is the code

$ find . -name "*.avi" -o -name "*.mkv" -exec basename \{} \ > ~/Bash/test/rm/films.txt
  • find: there is no argument to "-exec" Feb 26 '18 at 16:27
  • you're missing a ;. Also it appears to work for me but I don't believe there is any reason to escape {}
    – jesse_b
    Feb 26 '18 at 16:30

Try this instead :

$ find . \( -name "*.avi" -o -name "*.mkv" \) -exec basename {} \; > ~/Bash/test/rm/films.txt
  • I tried, the same thing Feb 26 '18 at 16:32
  • Thank you very much, your change worked, I so wanted to do, but I thought that after ";" code will not work anymore, Thanks again, your answer is the best Feb 26 '18 at 16:45
  • When you have multiple conditions, you should use parentheses like here, it's mandatory Feb 26 '18 at 16:49
  • @GillesQuenot It's only "mandatory" if the precedence of the conditions (OR/AND) matter.
    – Kusalananda
    Feb 26 '18 at 16:50
  • @Kusalananda: I agree Feb 26 '18 at 16:51

There are two typos in your command.

  1. \{} should be {}

  2. The \␣ (backslash+space) should be \; or ';'.

The -exec option/predicate of find needs to know where the command that it executes ends. It is told this by the ; at the end (which needs to be quoted to protect it from the shell).

You should not need to escape or quote {}.

There might be some issues with precedence too. You basically say

condition OR condition AND run-this-command

which is ambiguous. It would be better to say

(condition OR condition) AND run-this-command

This does that:

find . -type f '(' -name '*.avi' -o -name '*.mkv' ')' \
    -exec basename {} ';' > ~/Bash/test/rm/films.txt

I've also added -type f so that only regular files are considered.


Not the answer you're looking for? Browse other questions tagged or ask your own question.