簡體   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