0

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
Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

2 Answers2

4

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.

Kusalananda
  • 333,661
3

Try this instead :

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