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:
.
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. {}.html
to be supported, and so can work with any compliant find
. --
ensures that the following arguments are parsed as literal filenames, not options to mv
, even if they start with dashes. _
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.