我需要做一個bash命令來查看系統上的每個主目錄,並將.forward文件的內容複製到一個文件中,以及複製剛剛複製的目錄的名稱。因此,例如最終文件將類似forwards.txt和聆聽將是Bash腳本掃描子目錄並將文件的內容複製到另一個文件
/home/user1
[email protected]
/home/user2
[email protected]
我已經用它來列出它們到屏幕上。
find /home -name '*' | cat /home/*/.forward
它會打印出每個文件中的前進,但我沒有得到它前綴與它來自哪個主目錄。我需要使用循環來做到這一點嗎?我有這個測試循環,
#!/bin/bash
for i in /home/*
do
if [ -d $i ]
then
pwd >> /tmp/forwards.txt
cat /home/*/.forward >> /tmp/forwards.txt
fi
done
但它通過四個主目錄繼續我的測試設置和forwards.txt文件有以下列出的四倍。
/tmp
[email protected]
[email protected]
[email protected]
[email protected]
謝謝。腳本的
這感覺就像find'的'的組合和'-exec'可以使這一個單線(頭向他的Bash shell提示...) –