How to move files under multi-directories into same directory?
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO9GURib1T8z7lCwjOGLQaGtrueEthgQ8LO42ZX8cOfTqDK4jvDDpKkLFwf2J49kYCMNW7d4ABih_XCb_2UXdq5fPJDkoyg7-8g_YfRUot-XnaXkNYycsNp7lA5_TW9td0FFpLQ2APzKcZ/s1600/1.jpg)
![Creative The name of the picture](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYQ0N5W1qAOxLP7t7iOM6O6AzbZnkXUy16s7P_CWfOb5UbTQY_aDsc727chyphenhyphen5W4IppVNernMMQeaUFTB_rFzAd95_CDt-tnwN-nBx6JyUp2duGjPaL5-VgNO41AVsA_vu30EJcipdDG409/s400/Clash+Royale+CLAN+TAG%2523URR8PPP.png)
up vote
1
down vote
favorite
i have so many files under 300 different directories, file tree like:
--s1
- ----abc
- ----bcd
--s2
- ----123
- ----234
... etc.
I want to put them together under the same directory, like:
--whole
- ----abc
- ----bcd
- ----123
- ----234 ...
Is there any useful bash script in practical?
I coded this piece of bash script:
mkdir wavs
for ((i=1;i<=9;i++)); do
cd ~/wav/train/S000$i
mv * ~/wav/train/wavs
cd .. done
for ((i=10;i<=99;i++)); do
cd ~/wav/train/S00$i
mv * ~/wav/train/wavs
cd .. done
for ((i=100;i<=917;i++)); do
cd ~/wav/train/S0$i
mv * ~/wav/train/wavs
cd .. done
echo "ok"
but i got the error which i dont understand:
./untar.sh: line 24: cd: /wav/train/S0917: No such file or directory
cp: target '/wav/train/wavs/' is not a directory ok
command-line bash scripts directory mv
add a comment |Â
up vote
1
down vote
favorite
i have so many files under 300 different directories, file tree like:
--s1
- ----abc
- ----bcd
--s2
- ----123
- ----234
... etc.
I want to put them together under the same directory, like:
--whole
- ----abc
- ----bcd
- ----123
- ----234 ...
Is there any useful bash script in practical?
I coded this piece of bash script:
mkdir wavs
for ((i=1;i<=9;i++)); do
cd ~/wav/train/S000$i
mv * ~/wav/train/wavs
cd .. done
for ((i=10;i<=99;i++)); do
cd ~/wav/train/S00$i
mv * ~/wav/train/wavs
cd .. done
for ((i=100;i<=917;i++)); do
cd ~/wav/train/S0$i
mv * ~/wav/train/wavs
cd .. done
echo "ok"
but i got the error which i dont understand:
./untar.sh: line 24: cd: /wav/train/S0917: No such file or directory
cp: target '/wav/train/wavs/' is not a directory ok
command-line bash scripts directory mv
Hello, David, I've wrote an answer which usesfind
, that IMO is the easiest way to do this job. If you need to create a bash script here is provided two variants that solve a similar task: askubuntu.com/a/1020671/566421
â pa4080
Apr 2 at 9:57
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
i have so many files under 300 different directories, file tree like:
--s1
- ----abc
- ----bcd
--s2
- ----123
- ----234
... etc.
I want to put them together under the same directory, like:
--whole
- ----abc
- ----bcd
- ----123
- ----234 ...
Is there any useful bash script in practical?
I coded this piece of bash script:
mkdir wavs
for ((i=1;i<=9;i++)); do
cd ~/wav/train/S000$i
mv * ~/wav/train/wavs
cd .. done
for ((i=10;i<=99;i++)); do
cd ~/wav/train/S00$i
mv * ~/wav/train/wavs
cd .. done
for ((i=100;i<=917;i++)); do
cd ~/wav/train/S0$i
mv * ~/wav/train/wavs
cd .. done
echo "ok"
but i got the error which i dont understand:
./untar.sh: line 24: cd: /wav/train/S0917: No such file or directory
cp: target '/wav/train/wavs/' is not a directory ok
command-line bash scripts directory mv
i have so many files under 300 different directories, file tree like:
--s1
- ----abc
- ----bcd
--s2
- ----123
- ----234
... etc.
I want to put them together under the same directory, like:
--whole
- ----abc
- ----bcd
- ----123
- ----234 ...
Is there any useful bash script in practical?
I coded this piece of bash script:
mkdir wavs
for ((i=1;i<=9;i++)); do
cd ~/wav/train/S000$i
mv * ~/wav/train/wavs
cd .. done
for ((i=10;i<=99;i++)); do
cd ~/wav/train/S00$i
mv * ~/wav/train/wavs
cd .. done
for ((i=100;i<=917;i++)); do
cd ~/wav/train/S0$i
mv * ~/wav/train/wavs
cd .. done
echo "ok"
but i got the error which i dont understand:
./untar.sh: line 24: cd: /wav/train/S0917: No such file or directory
cp: target '/wav/train/wavs/' is not a directory ok
command-line bash scripts directory mv
command-line bash scripts directory mv
edited Apr 2 at 10:13
muru
130k19273463
130k19273463
asked Apr 2 at 8:56
David Aksnes
82
82
Hello, David, I've wrote an answer which usesfind
, that IMO is the easiest way to do this job. If you need to create a bash script here is provided two variants that solve a similar task: askubuntu.com/a/1020671/566421
â pa4080
Apr 2 at 9:57
add a comment |Â
Hello, David, I've wrote an answer which usesfind
, that IMO is the easiest way to do this job. If you need to create a bash script here is provided two variants that solve a similar task: askubuntu.com/a/1020671/566421
â pa4080
Apr 2 at 9:57
Hello, David, I've wrote an answer which uses
find
, that IMO is the easiest way to do this job. If you need to create a bash script here is provided two variants that solve a similar task: askubuntu.com/a/1020671/566421â pa4080
Apr 2 at 9:57
Hello, David, I've wrote an answer which uses
find
, that IMO is the easiest way to do this job. If you need to create a bash script here is provided two variants that solve a similar task: askubuntu.com/a/1020671/566421â pa4080
Apr 2 at 9:57
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Maybe the simplest way to do this job is by the command find
(by default it works recursively):
find ~/wav/train/S* -type f -name "*.wav" -exec echo mv ~/wav/train/wavs/ ;
~/wav/train/S*
is the search path and it will match to each sub dir that starts withS
.-type f
will limit the search only to the files.-name "*.wav"
will limit the search only to the files that ends with.wav
. Not mandatory.-exec ... ;
will execute the mentioned command once for each search coincidence.is a variable that contains the coincidence item.
remove
echo
from the commandecho mv ~/wav/train/wavs/
to do the action.
Further if you want to delete the directories you can use a command as one of these:
find ~/wav/train/S* -type d -name "S*" -exec echo rm -r ;
find ~/wav/train/S* -type d -name "S*" -delete
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Maybe the simplest way to do this job is by the command find
(by default it works recursively):
find ~/wav/train/S* -type f -name "*.wav" -exec echo mv ~/wav/train/wavs/ ;
~/wav/train/S*
is the search path and it will match to each sub dir that starts withS
.-type f
will limit the search only to the files.-name "*.wav"
will limit the search only to the files that ends with.wav
. Not mandatory.-exec ... ;
will execute the mentioned command once for each search coincidence.is a variable that contains the coincidence item.
remove
echo
from the commandecho mv ~/wav/train/wavs/
to do the action.
Further if you want to delete the directories you can use a command as one of these:
find ~/wav/train/S* -type d -name "S*" -exec echo rm -r ;
find ~/wav/train/S* -type d -name "S*" -delete
add a comment |Â
up vote
1
down vote
accepted
Maybe the simplest way to do this job is by the command find
(by default it works recursively):
find ~/wav/train/S* -type f -name "*.wav" -exec echo mv ~/wav/train/wavs/ ;
~/wav/train/S*
is the search path and it will match to each sub dir that starts withS
.-type f
will limit the search only to the files.-name "*.wav"
will limit the search only to the files that ends with.wav
. Not mandatory.-exec ... ;
will execute the mentioned command once for each search coincidence.is a variable that contains the coincidence item.
remove
echo
from the commandecho mv ~/wav/train/wavs/
to do the action.
Further if you want to delete the directories you can use a command as one of these:
find ~/wav/train/S* -type d -name "S*" -exec echo rm -r ;
find ~/wav/train/S* -type d -name "S*" -delete
add a comment |Â
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Maybe the simplest way to do this job is by the command find
(by default it works recursively):
find ~/wav/train/S* -type f -name "*.wav" -exec echo mv ~/wav/train/wavs/ ;
~/wav/train/S*
is the search path and it will match to each sub dir that starts withS
.-type f
will limit the search only to the files.-name "*.wav"
will limit the search only to the files that ends with.wav
. Not mandatory.-exec ... ;
will execute the mentioned command once for each search coincidence.is a variable that contains the coincidence item.
remove
echo
from the commandecho mv ~/wav/train/wavs/
to do the action.
Further if you want to delete the directories you can use a command as one of these:
find ~/wav/train/S* -type d -name "S*" -exec echo rm -r ;
find ~/wav/train/S* -type d -name "S*" -delete
Maybe the simplest way to do this job is by the command find
(by default it works recursively):
find ~/wav/train/S* -type f -name "*.wav" -exec echo mv ~/wav/train/wavs/ ;
~/wav/train/S*
is the search path and it will match to each sub dir that starts withS
.-type f
will limit the search only to the files.-name "*.wav"
will limit the search only to the files that ends with.wav
. Not mandatory.-exec ... ;
will execute the mentioned command once for each search coincidence.is a variable that contains the coincidence item.
remove
echo
from the commandecho mv ~/wav/train/wavs/
to do the action.
Further if you want to delete the directories you can use a command as one of these:
find ~/wav/train/S* -type d -name "S*" -exec echo rm -r ;
find ~/wav/train/S* -type d -name "S*" -delete
answered Apr 2 at 9:50
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
![](https://i.stack.imgur.com/Lrlbx.jpg?s=32&g=1)
pa4080
12.2k52256
12.2k52256
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1021266%2fhow-to-move-files-under-multi-directories-into-same-directory%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Hello, David, I've wrote an answer which uses
find
, that IMO is the easiest way to do this job. If you need to create a bash script here is provided two variants that solve a similar task: askubuntu.com/a/1020671/566421â pa4080
Apr 2 at 9:57