Moving folders with the same name to new directory Linux, Ubuntu -
i have folder 100,000 sub-folders. because of size cannot open folder. looking shell script me move or split folders.
current = folder research : 100,000 sub-folders. (sorted a, b, c, d)
needed = new folder folders starting name a-science. should moved new folder ascience. folders starting b-science.. should move new folder bscience
i found script below. don't know how make 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 @ command supplied see did. here's each command (correct me if i'm wrong)
| = pipes output of command left of pipe input of command on right find /home/spenx/src -name "a1a2*txt" = finds files within given directory match between "" , pipes output xargs -n 1 dirname = takes in piped files outputted find command , gets directory name of each file , pipes output xargs - list mv list /home/spenx/dst = takes in piped folders , and puts them list variable, mv items in list given folder find ~ -type d -name "**" -print = runs test files within given name see if exist , print found out (this line test command, it's not necessary actual move) /home/spenx/src = folder in (absolute file path, or folder name without '/') /home/spenx/dst = folder move files (absolute file path, or folder name without '/') "a1a2*txt" = files (since care folders, use *.* catch files "*99966* = files test i'm not sure put here
i took @ command , decided modify little, still won't move each folder category (i.e. a-science, b-science) separate dirs, folders in given directory , move them given destination, or @ least far can tell. might want try find folders of each category ( a-science) , moving them destination folder of ascience
1 one so
find /home/spenx/src -name "a-science/*.*" | xargs -n 1 dirname | sort -u | xargs - list mv list /home/spenx/dst/ascience
find /home/spenx/src -name "b-science/*.*" | xargs -n 1 dirname | sort -u | xargs - list mv list /home/spenx/dst/bscience
again, test command out before using on actual files.
you might want take @ this question, specifically:
list.txt
1abc 2def 3xyz
script run:
while read pattern; mv "${pattern}"* ../folder_b/"$pattern" done < list.txt
Comments
Post a Comment