尋找目錄並在找到的每個目錄中建立新的子目錄

尋找目錄並在找到的每個目錄中建立新的子目錄

我需要在find執行命令時建立的新子目錄中插入一個檔案。

# find /home/user*/.dir/anotherdir -maxdepth 1 -type d -iname "*.default" 
anotherdir/dwwcop9o.default
anotherdir/dge77smm.default

在上面的每個「尋找」結果中,我需要建立子目錄,以便目錄結構如下所示:

anotherdir/dwwcop9o.default/subdir
anotherdir/dge77smm.default/subdir

最後,在上面建立子目錄後,我需要在子目錄中插入一個檔案。

我該如何使用xargs,-exec或 來做到這一點-execdir

答案1

終於可以解決這個問題了,見下文。

# find /home/user*/.dir/anotherdir -maxdepth 1 -type d -iname "*.default" -exec mkdir {}/anotherdir \; -exec cp newfile {}/anotherdir \;

注意

newfile 必須位於目前工作目錄中,如果不是,請定義其絕對路徑。

相關內容