繁体   English   中英

将同名文件夹移动到新目录Linux,Ubuntu

[英]Moving folders with the same name to new directory Linux, Ubuntu

我有一个包含100,000个子文件夹的文件夹。 由于大小,我无法打开文件夹。 现在,我正在寻找一个Shell脚本来帮助我移动或拆分文件夹。

当前=文件夹研究:具有100,000个子文件夹。 (排序为A,B,C,D)

必需=新文件夹所有以名称A-science开头的文件夹。 应该移动到新的文件夹“科学”。 所有以B-Science ..开头的文件夹都应移至新的文件夹BScience

我在下面找到了这个脚本。 但是不知道如何使其工作。

find /home/spenx/src -name "a1a2*txt" | xargs -n 1 dirname | xargs -I list mv list /home/spenx/dst/
find ~ -type d -name "*99966*" -print

我看了您提供的命令以了解它的作用。 这是每个命令的功能(如果我输入错了,请纠正我)

| = pipes output of command to the left of pipe to the input of the command on the right
find /home/spenx/src -name "a1a2*txt" = finds all files within given directory that match between "" and pipes output 
xargs -n 1 dirname = takes in all the piped files outputted by the find command and gets the directory name of each file and pipes to output
xargs - I list mv list /home/spenx/dst = takes in all piped folders and and puts them into list variable, mv all items in list to the given folder
find ~ -type d -name "**" -print = runs a test for all files within given name to see if they exist and print any found out (this line is only a test command, it's not necessary for the actual move)


/home/spenx/src = folder to look in (absolute file path, or just folder name without '/')
/home/spenx/dst = folder to move all files to (absolute file path, or just folder name without '/')
"a1a2*txt" = files to look for (since you only care about folders, just use *.* to catch all files
"*99966* = files to test for but I'm not sure what you would put here

我看了一下命令并决定对其进行一些修改,但是它仍然不会将每个文件夹类别(即A-science,B-science)移动到一个单独的目录中,这只会将所有文件夹放在给定目录中并将它们移至给定的目的地,或者至少移至我所能告知的范围。 您可能想要尝试查找每个类别(A-Science)的所有文件夹,然后将它们一个接一个地Ascience的目标文件夹中。

find /home/spenx/src -name "A-science/*.*" | xargs -n 1 dirname | sort -u | xargs - I list mv list /home/spenx/dst/Ascience

find /home/spenx/src -name "B-science/*.*" | xargs -n 1 dirname | sort -u | xargs - I list mv list /home/spenx/dst/Bscience

同样,在实际文件上使用该命令之前,请先对其进行测试。

您可能想看一下这个问题 ,特别是:

LIST.TXT

1abc
2def
3xyz

要运行的脚本:

while read pattern; do
  mv "${pattern}"* ../folder_b/"$pattern"
done < list.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM