Moving multiple files having spaces in name (Linux)

谁都会走 提交于 2019-12-20 04:06:30

问题


I have a directory which contains multiple files with spaces in their names. I want to find a pattern in the name and those file will be moved to some other directory. Now the problem is that when the particular pattern is found in a single file name, that file is moving to the destination path but when there are multiple files this method fails. Below is the code that I'm using :

for file in `find . -maxdepth 1 -name "*$pattern*xlsx" -type f`
do
 mv "$file" $destination/
done

回答1:


No need to use a loop:

find . -maxdepth 1 -name "*$pattern*xlsx" -type f -exec mv {} $destination +



回答2:


Working fine with following code

find . -maxdepth 1 -name "*$pattern*xlsx" -type f -print0 | xargs -I{} -0 mv {} "$destination/"


来源:https://stackoverflow.com/questions/20781936/moving-multiple-files-having-spaces-in-name-linux

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!