I have the following folder setup on an ubuntu machine:
(brackets indicate folder)
[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
I need to find a quick way to replace all old [aaaa] and [bbbb] folders by their respective new [aaaa] and [bbbb] folders, without affecting any other old stuff.
You can do:
cd /main/old
find . -type d \( -name 'aaaa' -o -name '-bbbb' \) -exec cp -RfP {} ../new/{} \;
This is explicit and very standard
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 ../..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.