简体   繁体   English

如何使用find和xargs将文件从一个文件夹中的一个文件夹移动到另一个文件夹?

[英]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? 您根本不需要findxargs 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 在这些当中

  • Use find 's -exec option 使用find-exec选项
  • use 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.

相关问题 如何在 ssh 控制台中将文件夹的所有文件移动到另一个文件夹? - How to move all files of a folder to another folder in ssh console? “xargs -a file”将文件复制到文件夹 - “xargs -a file” to copy files to a folder 如何从 SFTP 服务器获取文件并将它们移动到 bash 脚本中的另一个文件夹? - How do I get the files from SFTP server and move them to another folder in bash script? 如何将文件从 docker 图像移动到计算机上的文件夹中 - How do i move files from a docker image into a folder on the computer 如何将所选文件一个文件夹移动到另一个带子文件夹的文件夹中 - How to move selected files one folder to another folder with sub folder also 将特定文件从一个文件夹移动到另一个文件夹的脚本 - Script to move specific files from one folder to another 在Linux中以maxdepth 2查找文件并移至相应的文件夹 - Find files with maxdepth 2 in Linux and move to respective folder Linux:查找大于500x500的图片,然后移至某个文件夹(Find + Xargs + Mv) - Linux: Find Images greater than 500x500 then move to some folder (Find+Xargs+Mv) 如何将文件从一个文件夹移动到另一个在特定日期创建的文件夹,给出 redhat 中的创建日期 - How can I move files from one folder to another created at specific date giving the creation date in redhat 如何将文件从一个文件夹复制到另一个文件夹 - How to copy a file from a folder to another folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM