Move folder structure across multiple directories [duplicate]
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
This question already has an answer here:
copy and rename files 2 directory up
4 answers
I am trying to move one a bunch of files at once, one directory up.
This is what I tried, but did not work:
mv ./*/__test__/index.js ./*/data.js
.
âÂÂâÂÂâ alpha
â âÂÂâÂÂâ __test__
â â âÂÂâÂÂâ index.js
â âÂÂâÂÂâ index.js
â âÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ __test__
â âÂÂâÂÂâ index.js
âÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
To this:
.
âÂÂâÂÂâ alpha
â âÂÂâÂÂâ data.js
â âÂÂâÂÂâ index.js
â âÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ data.js
âÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
How can I do this in unix?
files cp mv move
marked as duplicate by ñÃÂsýù÷, DopeGhoti, Gilles
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 24 at 20:07
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
4
down vote
favorite
This question already has an answer here:
copy and rename files 2 directory up
4 answers
I am trying to move one a bunch of files at once, one directory up.
This is what I tried, but did not work:
mv ./*/__test__/index.js ./*/data.js
.
âÂÂâÂÂâ alpha
â âÂÂâÂÂâ __test__
â â âÂÂâÂÂâ index.js
â âÂÂâÂÂâ index.js
â âÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ __test__
â âÂÂâÂÂâ index.js
âÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
To this:
.
âÂÂâÂÂâ alpha
â âÂÂâÂÂâ data.js
â âÂÂâÂÂâ index.js
â âÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ data.js
âÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
How can I do this in unix?
files cp mv move
marked as duplicate by ñÃÂsýù÷, DopeGhoti, Gilles
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 24 at 20:07
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
This question already has an answer here:
copy and rename files 2 directory up
4 answers
I am trying to move one a bunch of files at once, one directory up.
This is what I tried, but did not work:
mv ./*/__test__/index.js ./*/data.js
.
âÂÂâÂÂâ alpha
â âÂÂâÂÂâ __test__
â â âÂÂâÂÂâ index.js
â âÂÂâÂÂâ index.js
â âÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ __test__
â âÂÂâÂÂâ index.js
âÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
To this:
.
âÂÂâÂÂâ alpha
â âÂÂâÂÂâ data.js
â âÂÂâÂÂâ index.js
â âÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ data.js
âÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
How can I do this in unix?
files cp mv move
This question already has an answer here:
copy and rename files 2 directory up
4 answers
I am trying to move one a bunch of files at once, one directory up.
This is what I tried, but did not work:
mv ./*/__test__/index.js ./*/data.js
.
âÂÂâÂÂâ alpha
â âÂÂâÂÂâ __test__
â â âÂÂâÂÂâ index.js
â âÂÂâÂÂâ index.js
â âÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ __test__
â âÂÂâÂÂâ index.js
âÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
To this:
.
âÂÂâÂÂâ alpha
â âÂÂâÂÂâ data.js
â âÂÂâÂÂâ index.js
â âÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ data.js
âÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
How can I do this in unix?
This question already has an answer here:
copy and rename files 2 directory up
4 answers
files cp mv move
asked Mar 23 at 19:21
ThomasReggi
1957
1957
marked as duplicate by ñÃÂsýù÷, DopeGhoti, Gilles
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 24 at 20:07
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by ñÃÂsýù÷, DopeGhoti, Gilles
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 24 at 20:07
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
add a comment |Â
5 Answers
5
active
oldest
votes
up vote
4
down vote
You can't use wildcards in the target argument. So at least some scripting is required:
for d in *; do
if [[ -d "$d" ]]; then
pushd "$d"
mv __test__/index.js ./data.js
popd
fi
done
Look more closely. He wants to rename, not just move.
â Wildcard
Mar 23 at 19:33
@Wildcard Yeah, figured that out in the meantime :-)
â nohillside
Mar 23 at 19:35
add a comment |Â
up vote
2
down vote
Here is a example that will move the files.
for f in $(find -name index.js | grep __test__ ); do echo $f; destination=$(echo $f | awk 'BEGINFS="/" print $2'); mv $f ./$destination/data.js; done
I have tested this, it does perform the move as expected.
add a comment |Â
up vote
2
down vote
find . -path '*/__test__/*' -type f -name "index.js"
-execdir echo mv -vt ../data.js ;
Remove echo
which is for dry-run to run mv
command on files.
add a comment |Â
up vote
1
down vote
I forgot about gnu parallel
!
ls -d -- */ | parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null"
Or just:parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
â Ole Tange
Mar 27 at 17:06
add a comment |Â
up vote
1
down vote
Remove echo
s for the real changing.
for i in */__test__/index.js; do
echo mv -v "$i" "$i%%/*/data.js"
echo rm -vr "$i%/*"
done
Before
.
âÂÂâÂÂâ alpha
âÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ __test__
âÂÂààâÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ index.js
âÂÂâÂÂâ __test__
âÂÂààâÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
After
.
âÂÂâÂÂâ alpha
âÂÂààâÂÂâÂÂâ data.js
âÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ data.js
âÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
add a comment |Â
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
You can't use wildcards in the target argument. So at least some scripting is required:
for d in *; do
if [[ -d "$d" ]]; then
pushd "$d"
mv __test__/index.js ./data.js
popd
fi
done
Look more closely. He wants to rename, not just move.
â Wildcard
Mar 23 at 19:33
@Wildcard Yeah, figured that out in the meantime :-)
â nohillside
Mar 23 at 19:35
add a comment |Â
up vote
4
down vote
You can't use wildcards in the target argument. So at least some scripting is required:
for d in *; do
if [[ -d "$d" ]]; then
pushd "$d"
mv __test__/index.js ./data.js
popd
fi
done
Look more closely. He wants to rename, not just move.
â Wildcard
Mar 23 at 19:33
@Wildcard Yeah, figured that out in the meantime :-)
â nohillside
Mar 23 at 19:35
add a comment |Â
up vote
4
down vote
up vote
4
down vote
You can't use wildcards in the target argument. So at least some scripting is required:
for d in *; do
if [[ -d "$d" ]]; then
pushd "$d"
mv __test__/index.js ./data.js
popd
fi
done
You can't use wildcards in the target argument. So at least some scripting is required:
for d in *; do
if [[ -d "$d" ]]; then
pushd "$d"
mv __test__/index.js ./data.js
popd
fi
done
edited Mar 23 at 19:33
answered Mar 23 at 19:32
nohillside
1,868616
1,868616
Look more closely. He wants to rename, not just move.
â Wildcard
Mar 23 at 19:33
@Wildcard Yeah, figured that out in the meantime :-)
â nohillside
Mar 23 at 19:35
add a comment |Â
Look more closely. He wants to rename, not just move.
â Wildcard
Mar 23 at 19:33
@Wildcard Yeah, figured that out in the meantime :-)
â nohillside
Mar 23 at 19:35
Look more closely. He wants to rename, not just move.
â Wildcard
Mar 23 at 19:33
Look more closely. He wants to rename, not just move.
â Wildcard
Mar 23 at 19:33
@Wildcard Yeah, figured that out in the meantime :-)
â nohillside
Mar 23 at 19:35
@Wildcard Yeah, figured that out in the meantime :-)
â nohillside
Mar 23 at 19:35
add a comment |Â
up vote
2
down vote
Here is a example that will move the files.
for f in $(find -name index.js | grep __test__ ); do echo $f; destination=$(echo $f | awk 'BEGINFS="/" print $2'); mv $f ./$destination/data.js; done
I have tested this, it does perform the move as expected.
add a comment |Â
up vote
2
down vote
Here is a example that will move the files.
for f in $(find -name index.js | grep __test__ ); do echo $f; destination=$(echo $f | awk 'BEGINFS="/" print $2'); mv $f ./$destination/data.js; done
I have tested this, it does perform the move as expected.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
Here is a example that will move the files.
for f in $(find -name index.js | grep __test__ ); do echo $f; destination=$(echo $f | awk 'BEGINFS="/" print $2'); mv $f ./$destination/data.js; done
I have tested this, it does perform the move as expected.
Here is a example that will move the files.
for f in $(find -name index.js | grep __test__ ); do echo $f; destination=$(echo $f | awk 'BEGINFS="/" print $2'); mv $f ./$destination/data.js; done
I have tested this, it does perform the move as expected.
edited Mar 23 at 19:44
answered Mar 23 at 19:35
thebtm
645411
645411
add a comment |Â
add a comment |Â
up vote
2
down vote
find . -path '*/__test__/*' -type f -name "index.js"
-execdir echo mv -vt ../data.js ;
Remove echo
which is for dry-run to run mv
command on files.
add a comment |Â
up vote
2
down vote
find . -path '*/__test__/*' -type f -name "index.js"
-execdir echo mv -vt ../data.js ;
Remove echo
which is for dry-run to run mv
command on files.
add a comment |Â
up vote
2
down vote
up vote
2
down vote
find . -path '*/__test__/*' -type f -name "index.js"
-execdir echo mv -vt ../data.js ;
Remove echo
which is for dry-run to run mv
command on files.
find . -path '*/__test__/*' -type f -name "index.js"
-execdir echo mv -vt ../data.js ;
Remove echo
which is for dry-run to run mv
command on files.
answered Mar 23 at 20:18
ñÃÂsýù÷
14.8k82462
14.8k82462
add a comment |Â
add a comment |Â
up vote
1
down vote
I forgot about gnu parallel
!
ls -d -- */ | parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null"
Or just:parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
â Ole Tange
Mar 27 at 17:06
add a comment |Â
up vote
1
down vote
I forgot about gnu parallel
!
ls -d -- */ | parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null"
Or just:parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
â Ole Tange
Mar 27 at 17:06
add a comment |Â
up vote
1
down vote
up vote
1
down vote
I forgot about gnu parallel
!
ls -d -- */ | parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null"
I forgot about gnu parallel
!
ls -d -- */ | parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null"
answered Mar 23 at 19:38
ThomasReggi
1957
1957
Or just:parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
â Ole Tange
Mar 27 at 17:06
add a comment |Â
Or just:parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
â Ole Tange
Mar 27 at 17:06
Or just:
parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
â Ole Tange
Mar 27 at 17:06
Or just:
parallel "cd && mv ./__test__/index.js ./data.js 2>/dev/null" ::: */
â Ole Tange
Mar 27 at 17:06
add a comment |Â
up vote
1
down vote
Remove echo
s for the real changing.
for i in */__test__/index.js; do
echo mv -v "$i" "$i%%/*/data.js"
echo rm -vr "$i%/*"
done
Before
.
âÂÂâÂÂâ alpha
âÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ __test__
âÂÂààâÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ index.js
âÂÂâÂÂâ __test__
âÂÂààâÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
After
.
âÂÂâÂÂâ alpha
âÂÂààâÂÂâÂÂâ data.js
âÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ data.js
âÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
add a comment |Â
up vote
1
down vote
Remove echo
s for the real changing.
for i in */__test__/index.js; do
echo mv -v "$i" "$i%%/*/data.js"
echo rm -vr "$i%/*"
done
Before
.
âÂÂâÂÂâ alpha
âÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ __test__
âÂÂààâÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ index.js
âÂÂâÂÂâ __test__
âÂÂààâÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
After
.
âÂÂâÂÂâ alpha
âÂÂààâÂÂâÂÂâ data.js
âÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ data.js
âÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Remove echo
s for the real changing.
for i in */__test__/index.js; do
echo mv -v "$i" "$i%%/*/data.js"
echo rm -vr "$i%/*"
done
Before
.
âÂÂâÂÂâ alpha
âÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ __test__
âÂÂààâÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ index.js
âÂÂâÂÂâ __test__
âÂÂààâÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
After
.
âÂÂâÂÂâ alpha
âÂÂààâÂÂâÂÂâ data.js
âÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ data.js
âÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
Remove echo
s for the real changing.
for i in */__test__/index.js; do
echo mv -v "$i" "$i%%/*/data.js"
echo rm -vr "$i%/*"
done
Before
.
âÂÂâÂÂâ alpha
âÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ __test__
âÂÂààâÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ index.js
âÂÂâÂÂâ __test__
âÂÂààâÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
After
.
âÂÂâÂÂâ alpha
âÂÂààâÂÂâÂÂâ data.js
âÂÂààâÂÂâÂÂâ index.js
âÂÂààâÂÂâÂÂâ test.js
âÂÂâÂÂâ beta
âÂÂâÂÂâ data.js
âÂÂâÂÂâ index.js
âÂÂâÂÂâ test.js
answered Mar 23 at 20:46
MiniMax
2,681718
2,681718
add a comment |Â
add a comment |Â