2013-07-28 176 views
0

我想有一個bash腳本循環通過一個目錄樹,並使符號鏈接到一個新的目錄白樹,但改變文件的名稱,以告訴目錄的新名稱。符號鏈接目錄樹到一個目錄

事情是這樣的:

來源:

目錄

- DirectoryA

---- DirectoryAA

------ FileAA1

- ----- FileAA2

---- FileA1

---- FileA2

- DirectoryB

---- FileB1

- DirectoryC

---- FileC1

---- FileC2

---- FileC3

目的地:

DirectoryDe​​st

--DirectoryA - DirectoryAA - FileAA1

--DirectoryA - DirectoryAA - FileAA2

--DirectoryA - FileA1

- -DirectoryA - FileA2

--DirectoryB - FileB1

--DirectoryC - FileC1

--DirectoryC - FileC2

--DirectoryC - FileC3

+0

在混凝土中沒有,無法想象的方式來做到這一點,需要一些Kickstart中 – nan4k7

回答

0

這應做到:

cd Directory; find * -type f -print0 | xargs -l -0 bash -c 'filename=`echo "$0" | tr '/' -`; ln -s $(pwd)/$0 ../DirectoryDest/$filename' 

這將導致這些文件:

[email protected]:~$ ls -l DirectoryDest/ 
total 0 
lrwxrwxrwx 1 user user 51 Jul 27 23:02 DirectoryA-DirectoryAA-FileAA1 -> /home/user/Directory/DirectoryA/DirectoryAA/FileAA1 
lrwxrwxrwx 1 user user 51 Jul 27 23:02 DirectoryA-DirectoryAA-FileAA2 -> /home/user/Directory/DirectoryA/DirectoryAA/FileAA2 
lrwxrwxrwx 1 user user 38 Jul 27 23:02 DirectoryA-FileA1 -> /home/user/Directory/DirectoryA/FileA1 
lrwxrwxrwx 1 user user 38 Jul 27 23:02 DirectoryA-FileA2 -> /home/user/Directory/DirectoryA/FileA2 
lrwxrwxrwx 1 user user 38 Jul 27 23:02 DirectoryB-FileB1 -> /home/user/Directory/DirectoryB/FileB1 
lrwxrwxrwx 1 user user 38 Jul 27 23:02 DirectoryC-FileC1 -> /home/user/Directory/DirectoryC/FileC1 
lrwxrwxrwx 1 user user 38 Jul 27 23:02 DirectoryC-FileC2 -> /home/user/Directory/DirectoryC/FileC2 
lrwxrwxrwx 1 user user 38 Jul 27 23:02 DirectoryC-FileC3 -> /home/user/Directory/DirectoryC/FileC3 
+0

onionjake,我不能讓你的答案的工作,我使用在OpenWrt的BusyBox的和xargs的不具有PARAMS ... – nan4k7

+0

哪些參數?嘗試'-L 1'而不是'-l'。 – onionjake

+0

它也可以在不使用xargs的情況下重寫。請參閱http://stackoverflow.com/questions/8759285/alternatives-to-xargs-l – onionjake

相關問題