[英]How do you use find and xargs to move files from a folder within a folder to another folder?
I am trying to move files within the filecontainer folder into the example1 folder. 我正在尝试将filecontainer文件夹中的文件移动到example1文件夹中。
The directory structure is: 目录结构为:
/example1
/example2/filecontainer
example1 has nothing in it. example1中没有任何内容。
example2 has a folder named filecontainer and three files in it called example1.sh, example2.sh and example3.sh example2有一个名为filecontainer的文件夹,其中有三个文件,分别为example1.sh,example2.sh和example3.sh
I tried the command below but none of the files were moved. 我尝试了下面的命令,但是没有文件被移动。
find ./ -name "example*.sh" | xargs -I% mv % example1
Essentially I want to move files within a subfolder to another folder. 本质上,我想将子文件夹中的文件移动到另一个文件夹。 I am able to move files from a folder to another but when it the folder is a subfolder, it does not work.
我可以将文件从一个文件夹移动到另一个文件夹,但是当该文件夹是子文件夹时,它将不起作用。
I have to use the find and xargs since I will later on filter files from today up to a year and only move those files from a sub folder to a folder. 我必须使用find和xargs,因为以后我将使用从今天到一年的筛选器文件,并将这些文件从子文件夹移动到文件夹。
you don't need find
or xargs
at all? 您根本不需要
find
或xargs
? Your shell will happily do things for you: 您的Shell会很乐意为您做事:
mv -t /example1 /example2/filecontainer/example.*
if you indeed got a more complicated scheme where you actually need find, you can do a number of things; 如果确实有一个实际上需要查找的更复杂的方案,则可以做很多事情; among these
在这些当中
find
's -exec
option find
的-exec
选项 find [location] [-options, such as -name] -print0 | xargs -0 mv -t {target directory}
find [location] [-options, such as -name] -print0 | xargs -0 mv -t {target directory}
find [location] [-options, such as -name] -print0 | xargs -0 mv -t {target directory}
. find [location] [-options, such as -name] -print0 | xargs -0 mv -t {target directory}
。 Note that -print0
makes find separate the file names with a zero byte, which is great, because other delimiters like spaces or newlines are absolutely legal to have in file names; -print0
可以用零字节分开查找文件名,这很好,因为文件名中的其他分隔符(如空格或换行符)绝对合法。 -0
makes xargs look for zero bytes instead of linebreaks -0
使xargs查找零字节而不是换行符 The problem with your code, by the way, is that you're using very strange quotation marks: your “
isn't "
, and it makes a difference for your computer. 顺便说一句,代码的问题是您使用了非常奇怪的引号:您的
“
不是"
,这对您的计算机有所不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.