GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu)
Ubuntu 20.04.3 LTS
So, I downloaded like 20 7z files and I wanted to move them somewhere, but NOT the previous 7z files I already had in Downloads. (The filenames had some spaces in them, too, btw.) So I did like
mv `find -mmin -700 -iname "*.7z" -printf "\"%f\" "` ~/FOLDER/
which should have found all 7z files modified in the last ~11 hrs or so, and moved them to ~/FOLDER/.
Instead of moving all the files, it gives me a heap of errors with fragments of the filenames, like
mv: cannot stat 'Pinball': No such file or directory
I've tried the find
command on its own, and it gives me a reasonable-looking list of files, each surrounded by quotes, all on one line. I ALSO tried pasting the output of the find
command into mv PASTED_HERE ~/FOLDER/
, like I thought the backticks basically DID, and it worked fine. (I also tried $()
instead of the backticks, but I got the same errors as with the backticks.) What's going wrong?
mv $(find …) …
(or equivalent with backticks) is basically as flawed asfor f in $(find …); do …
, the Bash pitfall number 1."hello $(bad command) && echo foo"
, and it would work fine withrm ./*
, or indeed if the name was contained in a variable, and you didrm "$filename"
. Zsh doesn't do word splitting on variables by default, (err, but I think it does on command substitutions, for some reason) and it has better tools on controlling it too, and for using the output of e.g.find -print0
.