[英]Moving folders with the same name to new directory Linux, Ubuntu
I have a folder with 100,000 sub-folders. 我有一个包含100,000个子文件夹的文件夹。 Because of the size I cannot open the folder.
由于大小,我无法打开文件夹。 Now I am looking for a shell script to help me move or split the folders.
现在,我正在寻找一个Shell脚本来帮助我移动或拆分文件夹。
Current = Folder Research : with 100,000 sub-folders. 当前=文件夹研究:具有100,000个子文件夹。 (Sorted A, B, C, D)
(排序为A,B,C,D)
Needed = New folder All folders starting with name A-science. 必需=新文件夹所有以名称A-science开头的文件夹。 should be moved to a new folder AScience.
应该移动到新的文件夹“科学”。 All folders starting with B-Science.. should be move to a new folder BScience
所有以B-Science ..开头的文件夹都应移至新的文件夹BScience
I found this script below. 我在下面找到了这个脚本。 But don't know how to make it work.
但是不知道如何使其工作。
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
I had a look at the command you supplied to see what it did. 我看了您提供的命令以了解它的作用。 here's what each command does (correct me if I'm wrong)
这是每个命令的功能(如果我输入错了,请纠正我)
| = 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
I took a look at the command and decided to modify it a little, but It still won't move each folder category (ie A-science, B-science) into a separate dirs, this will just get all folders in a given directory and move them to a given destination, or at least as far as I can tell. 我看了一下命令并决定对其进行一些修改,但是它仍然不会将每个文件夹类别(即A-science,B-science)移动到一个单独的目录中,这只会将所有文件夹放在给定目录中并将它们移至给定的目的地,或者至少移至我所能告知的范围。 You might want to try find all folders of each category ( A-Science) and moving them to a destination folder of
Ascience
one by one like so 您可能想要尝试查找每个类别(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
Again, test the command out before using it on your actual files. 同样,在实际文件上使用该命令之前,请先对其进行测试。
You might want to take look at this question , specifically: 您可能想看一下这个问题 ,特别是:
list.txt LIST.TXT
1abc
2def
3xyz
script to run: 要运行的脚本:
while read pattern; do
mv "${pattern}"* ../folder_b/"$pattern"
done < list.txt
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.