简体   繁体   English

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

[英]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.

相关问题 将所有文件夹和文件移动到 Linux 目录中具有相同主题名称的文件夹中 - move all the folders and files to the folder with the same subject name in the directory Linux Linux:如何将具有新名称的文件复制到同一目录中? - Linux: how to copy a file with a new name into the same directory? ubuntu / linux中具有相同名称的多个二进制文件 - multiple binaries with same name in ubuntu/linux 在linux中,将多个目录中的同名文件复制到一个以路径不同为名称的新目录中 - In linux, copy files with the same name in multiple directories, to a new directory with the path difference as name Linux脚本创建名称为datestamp的新目录 - Linux script to create new directory with name as datestamp Linux:查找所有具有特定名称的文件夹,将其删除,然后将一个文件夹复制到这些文件夹的父目录中 - Linux: Find all folders with a particular name, remove them and have a folder copied into the parent directory of those folders 将文件移动到其他Linux目录 - Moving files to different linux directory 如何根据 linux 中的名称将文件移动到新目录? - How do I move files to a new directory based on their name in linux? Linux Ubuntu和Symfony缓存目录 - Linux Ubuntu and Symfony cache directory Linux Ubuntu目录根目录? 家? - Linux Ubuntu directory root? home?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM