简体   繁体   中英

Find: missing argument to `-execdir'

I'm working in win 10 with git-bash. I have a large group of files all of which have no extension. However I've realized that those of type "File" are html files. To select these I have been shown:

$ find -not -name '*.*'

Now I need to rename all these files to add a .html extension (they currently have no extension). I've tried :

$ find -not -name '*.*' -execdir mv {} {}.html
find: missing argument to `-execdir'

How can I rename these files?

You're missing a ; -- a literal semicolon passed to signal the end of the arguments parsed as part of the -exec action. Accepting such a terminator lets find accept other actions following -exec , whereas otherwise any action in that family would need to be the very last argument on the command line.

find -not -name '*.*' -execdir mv -- '{}' '{}.html' ';'

That said, note that the above isn't guaranteed to work at all (or to work with names that start with dashes). More portable would be:

find . -not -name '*.*' -exec sh -c 'for arg do mv -- "$arg" "$arg.html"; done' _ {} +

Note the changes:

  • The . specifying the directory to start the search at is mandatory in POSIX-standard find ; the ability to leave it out on GNU platforms is a nonportable extension.
  • Running an explicit shell means you don't need {}.html to be supported, and so can work with any compliant find .
  • The -- ensures that the following arguments are parsed as literal filenames, not options to mv , even if they start with dashes.
  • In the above, the explicit _ becomes $0 of the shell, so later arguments become $1 and onward -- ie. the array otherwise known as "$@" , which for iterates over by default.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM