移动名称中有空格的多个文件(Linux) [英] Moving multiple files having spaces in name (Linux)

查看:143
本文介绍了移动名称中有空格的多个文件(Linux)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目录,其中包含多个文件,其名称中包含空格。我想在名称中找到一个模式,这些文件将被移动到其他目录。现在的问题是,当在一个文件名中找到特定的模式时,该文件正在移动到目标路径,但是当有多个文件时,此方法失败。以下是我正在使用的代码:

 用于find中的文件。 -maxdepth 1 -name* $ pattern * xlsx-type f` 
do
mv$ file$ destination /
done


解决方案

不需要使用循环:

<$ p $找到> 。 -maxdepth 1 -name* $ pattern * xlsx-type f -exec mv {} $ destination +


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

解决方案

No need to use a loop:

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

这篇关于移动名称中有空格的多个文件(Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆