我在ubuntu机器上设置了以下文件夹:
(括号表示文件夹)
[main]
|
|--- [old]
| |
| |--- [thequick]
| | |
| | |--- [aaaa] --- some files
| | |--- [bbbb] --- some files
| | |--- [cccc] --- some files
| | |--- [dddd] --- some files
| | |--- some files
| |
| |--- [brownfox]
| | |
| | |--- [aaaa] --- some files
| | |--- [bbbb] --- some files
| | |--- [cccc] --- some files
| | |--- [dddd] --- some files
| | |--- some files
| |--- ...
| |
| |--- [lazydog]
| |
| |--- [aaaa] --- some files
| |--- [bbbb] --- some files
| |--- [cccc] --- some files
| |--- [dddd] --- some files
| |--- some files
|
|--- [new]
|
|--- [thequick]
| |
| |--- [aaaa] --- some files
| |--- [bbbb] --- some files
| |--- some files
|
|--- [brownfox]
| |
| |--- [aaaa] --- some files
| |--- [bbbb] --- some files
| |--- some files
|--- ...
|
|--- [lazydog]
|
|--- [aaaa] --- some files
|--- [bbbb] --- some files
|--- some files
我需要找到一种快速方法,用各自的新 [aaaa]和[bbbb]文件夹替换所有旧 [aaaa]和[bbbb]文件夹,< strong>不影响任何其他旧东西。
答案 0 :(得分:2)
你可以这样做:
cd /main/old
find . -type d \( -name 'aaaa' -o -name '-bbbb' \) -exec cp -RfP {} ../new/{} \;
答案 1 :(得分:0)
这是明确且非常标准的
cd main/old
for dir in `find . \( -name aaaa -o -name bbbb \) -a -type d`
do
(
cd ..
if [ -d new/$dir ]
then
rm -rf old/$dir
mv new/$dir old/$dir
fi
)
done
cd ../..