You are not logged in.
Hello everybody!
I am trying to move multiple 'pdf' files containing specific word in the filename from different folders to a new folder on another partition.
I am using the 'mv' command
mv $(fd linux | grep pdf) /new/partition/new/folder/It works as long as there are no spaces in the filenames.
If there are spaces in the filename I get
mv: cannot stat 'Downloads/Linux': No such file or directory
mv: cannot stat 'commands': No such file or directory
mv: cannot stat 'cheat': No such file or directory
mv: cannot stat 'sheet': No such file or directory
mv: cannot stat 'by': No such file or directory
mv: cannot stat 'PhoenixNAP.pdf': No such file or directoryI did some gooooooogling and found an alternative way to do it
fd linux | grep pdf > pdf_list
while IFS= read -r file; do mv -- "$file" "/new/partition/new/folder/"; done < pdf_listAny suggestions how to avoid errors with the 'mv' command when the 'fd' command finds file(s) with spaces in the filename are appreciated!
Thank you in advance!
Last edited by amaro (2021-06-27 10:02:52)
Offline
How about the -exec flag of find?
find -iname '*linux*.pdf' -exec mv {} /new/location/ \;
Last edited by flyingscorpio (2021-06-27 09:27:20)
Offline
find -name '*linux*.pdf' -exec mv '{}' /new/partition/new/folder/ \;I think the equivalent using fd is:
fd -g '*linux*.pdf' -x mv '{}' /new/partition/new/folder/ \;Offline
I tried
find . -iname "quotes" -exec mv {} /new/partition/new/folder \;but no file was moved.
Offline
Why did you use "quotes" instead of '*linux*.pdf' ? Was that the actual command?
Edit:
$ mkdir -p src/subdir dest/anotherdir
$ touch 'src/subdir/some name with linux in it .pdf'
$ find src dest
src
src/subdir
src/subdir/some name with linux in it .pdf
dest
dest/anotherdir
$ find -name '*linux*.pdf' -exec mv '{}' dest/anotherdir \;
find src dest
src
src/subdir
dest
dest/anotherdir
dest/anotherdir/some name with linux in it .pdfLast edited by loqs (2021-06-27 09:48:29)
Offline
@loqs
I am moving lots of files. The 'quotes' was used when I tried to move files containing 'quotes' in the filename. Used it to show the command I tried.
Anyway, I have just tried your version of the 'find' command with the word 'linux'.
$ fd linux | grep pdf
Downloads/Linux commands cheat sheet by PhoenixNAP.pdf
$ find -name '*linux*.pdf' -exec mv '{}' /new/partition/TB/quotes/ \;
$ ls /new/partition/TB/quotes/It did not work.
So I tried the 'fd' command you suggested
$ fd -g '*linux*.pdf' -x mv '{}' /new/partition/TB/quotes/ \;
$ ls /new/partition/TB/quotes/
'Linux commands cheat sheet by PhoenixNAP.pdf'It worked.
Thank you, loqs!
Last edited by amaro (2021-06-27 09:57:26)
Offline
$ fd linux | grep pdf
Downloads/Linux commands cheat sheet by PhoenixNAP.pdf
$ find -name '*linux*.pdf' -exec mv '{}' /new/partition/TB/quotes/ \;
$ ls /new/partition/TB/quotes/Case mismatch linux will not match Linux using -name you would need -iname.
Offline
Absolutely!
Thank you once again, loqs!
Offline