How to move content of a folder to current folder?
Clash Royale CLAN TAG#URR8PPP
up vote
5
down vote
favorite
I have this folder structure:
foo
`----> bar
How can I extract the content of bar
into foo
?
I tried mv -f bar/* .
from within foo
.
-f, --force | dont't ask before overwrite
but I get "could not move bar/ajax
to foo/ajax
because the directory is not empty"
How can I solve this?
cp mv
add a comment |Â
up vote
5
down vote
favorite
I have this folder structure:
foo
`----> bar
How can I extract the content of bar
into foo
?
I tried mv -f bar/* .
from within foo
.
-f, --force | dont't ask before overwrite
but I get "could not move bar/ajax
to foo/ajax
because the directory is not empty"
How can I solve this?
cp mv
mv
complains for reasons, in the end it depends what exactly you want to happen when there are folders and files to be overwritten... There are also some corner cases to take note of, e.g. what happens when there is abar/bar/
, or other conflicts.
â frostschutz
Jul 5 at 11:02
Is there anything else in foo? (is it just bar?)
â ctrl-alt-delor
Jul 5 at 18:11
@ctrl-alt-delor, there are many other files and folders in foo
â Black
Jul 6 at 8:04
It is best to edit the question, so that people see it (not just leave amendments in the comments).
â ctrl-alt-delor
Jul 6 at 8:04
add a comment |Â
up vote
5
down vote
favorite
up vote
5
down vote
favorite
I have this folder structure:
foo
`----> bar
How can I extract the content of bar
into foo
?
I tried mv -f bar/* .
from within foo
.
-f, --force | dont't ask before overwrite
but I get "could not move bar/ajax
to foo/ajax
because the directory is not empty"
How can I solve this?
cp mv
I have this folder structure:
foo
`----> bar
How can I extract the content of bar
into foo
?
I tried mv -f bar/* .
from within foo
.
-f, --force | dont't ask before overwrite
but I get "could not move bar/ajax
to foo/ajax
because the directory is not empty"
How can I solve this?
cp mv
edited Jul 5 at 10:33
asked Jun 21 at 11:59
Black
4932728
4932728
mv
complains for reasons, in the end it depends what exactly you want to happen when there are folders and files to be overwritten... There are also some corner cases to take note of, e.g. what happens when there is abar/bar/
, or other conflicts.
â frostschutz
Jul 5 at 11:02
Is there anything else in foo? (is it just bar?)
â ctrl-alt-delor
Jul 5 at 18:11
@ctrl-alt-delor, there are many other files and folders in foo
â Black
Jul 6 at 8:04
It is best to edit the question, so that people see it (not just leave amendments in the comments).
â ctrl-alt-delor
Jul 6 at 8:04
add a comment |Â
mv
complains for reasons, in the end it depends what exactly you want to happen when there are folders and files to be overwritten... There are also some corner cases to take note of, e.g. what happens when there is abar/bar/
, or other conflicts.
â frostschutz
Jul 5 at 11:02
Is there anything else in foo? (is it just bar?)
â ctrl-alt-delor
Jul 5 at 18:11
@ctrl-alt-delor, there are many other files and folders in foo
â Black
Jul 6 at 8:04
It is best to edit the question, so that people see it (not just leave amendments in the comments).
â ctrl-alt-delor
Jul 6 at 8:04
mv
complains for reasons, in the end it depends what exactly you want to happen when there are folders and files to be overwritten... There are also some corner cases to take note of, e.g. what happens when there is a bar/bar/
, or other conflicts.â frostschutz
Jul 5 at 11:02
mv
complains for reasons, in the end it depends what exactly you want to happen when there are folders and files to be overwritten... There are also some corner cases to take note of, e.g. what happens when there is a bar/bar/
, or other conflicts.â frostschutz
Jul 5 at 11:02
Is there anything else in foo? (is it just bar?)
â ctrl-alt-delor
Jul 5 at 18:11
Is there anything else in foo? (is it just bar?)
â ctrl-alt-delor
Jul 5 at 18:11
@ctrl-alt-delor, there are many other files and folders in foo
â Black
Jul 6 at 8:04
@ctrl-alt-delor, there are many other files and folders in foo
â Black
Jul 6 at 8:04
It is best to edit the question, so that people see it (not just leave amendments in the comments).
â ctrl-alt-delor
Jul 6 at 8:04
It is best to edit the question, so that people see it (not just leave amendments in the comments).
â ctrl-alt-delor
Jul 6 at 8:04
add a comment |Â
5 Answers
5
active
oldest
votes
up vote
7
down vote
accepted
mv
will overwrite files, but it will refuse to overwrite directories. There's no single command that will merge directories and remove the source directories (which is probably what you want with mv
). Even rsync --remove-source-files
will leave empty directories.
You can use a combination of commands:
cp -a dev/. .
rm -r dev
which copies everything in dev
to the current directory and then removes the dev
directory.
Or:
rsync -a --remove-source-files dev/ .
find dev -depth -type d -exec rmdir ;
which uses rsync
to move all the files, and then deletes the empty directories left behind.
add a comment |Â
up vote
1
down vote
The reference manual of mv
clearly states how to use the --force
option.
If a destination file exists but is normally unwritable, standard
input is a terminal, and the âÂÂ-fâ or âÂÂ--forceâ option is not given, âÂÂmvâÂÂ
prompts the user for whether to replace the file. (You might own the
file, or have write permission on its directory.) If the response is
not affirmative, the file is skipped.
Moreover, the manual highlights why mv
will never replace non-empty directories.
Note: âÂÂmvâ will only replace empty directories in the destination.
Conflicting populated directories are skipped with a diagnostic.
One way is to move files and directories without deleting existing contents in the target directory.
-b, --backup[=METHOD]
Make a backup of each file that would otherwise be overwritten or removed.
All files and directories are moved without issue and nobody does not loose its data.
prompt% mv -b /foo_path/bar/* /foo_path
prompt% rmdir -v /foo_path/bar
add a comment |Â
up vote
1
down vote
Issue at Hand
You wish to move the contents of foo/bar/
up a level to foo/
.
I will be referencing this post on superuser as well as this post from serverfault in the solution.
Solution
According to user Stephan202, you are looking for the following commands to execute this task:
cd /path/to/foo/bar
mv * .[^.]* ..
It should also be possible, from within foo/bar/
, to run the following command as well:
(shopt -s dotglob; mv -- * ..)
Verify you have the correct permissions as well. If needed run the command with root(sudo) privileges.
Conclusion
Please comment if you have any questions or issues with this answer. I highly suggest you read through each link I have provided thoroughly before attempting the commands. I appreciate feedback to correct any misconceptions and to improve my posts. I can update my answer as needed.
Best of Luck!
add a comment |Â
up vote
0
down vote
If you have a directory foo
that only contains a directory bar
. (bar
may contain other stuff).
And you want to rename foo/bar
â foo
, then do:
mv -T foo foo.original
mv -T foo.original/bar foo
rmdir foo.original
You can leave of the -T
if your mv
does not have this option, however it makes it safer.
add a comment |Â
up vote
-2
down vote
Simply use the move command :
cd foo
mv bar/* .
As Jeff Schaller suggest, use
shopt -s dotglob
before the mv command to move hidden files and use the option -i
of mv if you want an interactive check before overwriting
In bash, consider setting dotglob so that this picks up âÂÂhiddenâ files.
â Jeff Schaller
Jun 21 at 12:05
Note that this may overwrite files that have the same names in both folders, and that hidden files are skipped.
â Kusalananda
Jun 21 at 12:06
1
Does not work, I get `Not possible because the directory is not empty"
â Black
Jul 5 at 10:30
add a comment |Â
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
7
down vote
accepted
mv
will overwrite files, but it will refuse to overwrite directories. There's no single command that will merge directories and remove the source directories (which is probably what you want with mv
). Even rsync --remove-source-files
will leave empty directories.
You can use a combination of commands:
cp -a dev/. .
rm -r dev
which copies everything in dev
to the current directory and then removes the dev
directory.
Or:
rsync -a --remove-source-files dev/ .
find dev -depth -type d -exec rmdir ;
which uses rsync
to move all the files, and then deletes the empty directories left behind.
add a comment |Â
up vote
7
down vote
accepted
mv
will overwrite files, but it will refuse to overwrite directories. There's no single command that will merge directories and remove the source directories (which is probably what you want with mv
). Even rsync --remove-source-files
will leave empty directories.
You can use a combination of commands:
cp -a dev/. .
rm -r dev
which copies everything in dev
to the current directory and then removes the dev
directory.
Or:
rsync -a --remove-source-files dev/ .
find dev -depth -type d -exec rmdir ;
which uses rsync
to move all the files, and then deletes the empty directories left behind.
add a comment |Â
up vote
7
down vote
accepted
up vote
7
down vote
accepted
mv
will overwrite files, but it will refuse to overwrite directories. There's no single command that will merge directories and remove the source directories (which is probably what you want with mv
). Even rsync --remove-source-files
will leave empty directories.
You can use a combination of commands:
cp -a dev/. .
rm -r dev
which copies everything in dev
to the current directory and then removes the dev
directory.
Or:
rsync -a --remove-source-files dev/ .
find dev -depth -type d -exec rmdir ;
which uses rsync
to move all the files, and then deletes the empty directories left behind.
mv
will overwrite files, but it will refuse to overwrite directories. There's no single command that will merge directories and remove the source directories (which is probably what you want with mv
). Even rsync --remove-source-files
will leave empty directories.
You can use a combination of commands:
cp -a dev/. .
rm -r dev
which copies everything in dev
to the current directory and then removes the dev
directory.
Or:
rsync -a --remove-source-files dev/ .
find dev -depth -type d -exec rmdir ;
which uses rsync
to move all the files, and then deletes the empty directories left behind.
answered Jul 5 at 10:58
muru
33.1k576140
33.1k576140
add a comment |Â
add a comment |Â
up vote
1
down vote
The reference manual of mv
clearly states how to use the --force
option.
If a destination file exists but is normally unwritable, standard
input is a terminal, and the âÂÂ-fâ or âÂÂ--forceâ option is not given, âÂÂmvâÂÂ
prompts the user for whether to replace the file. (You might own the
file, or have write permission on its directory.) If the response is
not affirmative, the file is skipped.
Moreover, the manual highlights why mv
will never replace non-empty directories.
Note: âÂÂmvâ will only replace empty directories in the destination.
Conflicting populated directories are skipped with a diagnostic.
One way is to move files and directories without deleting existing contents in the target directory.
-b, --backup[=METHOD]
Make a backup of each file that would otherwise be overwritten or removed.
All files and directories are moved without issue and nobody does not loose its data.
prompt% mv -b /foo_path/bar/* /foo_path
prompt% rmdir -v /foo_path/bar
add a comment |Â
up vote
1
down vote
The reference manual of mv
clearly states how to use the --force
option.
If a destination file exists but is normally unwritable, standard
input is a terminal, and the âÂÂ-fâ or âÂÂ--forceâ option is not given, âÂÂmvâÂÂ
prompts the user for whether to replace the file. (You might own the
file, or have write permission on its directory.) If the response is
not affirmative, the file is skipped.
Moreover, the manual highlights why mv
will never replace non-empty directories.
Note: âÂÂmvâ will only replace empty directories in the destination.
Conflicting populated directories are skipped with a diagnostic.
One way is to move files and directories without deleting existing contents in the target directory.
-b, --backup[=METHOD]
Make a backup of each file that would otherwise be overwritten or removed.
All files and directories are moved without issue and nobody does not loose its data.
prompt% mv -b /foo_path/bar/* /foo_path
prompt% rmdir -v /foo_path/bar
add a comment |Â
up vote
1
down vote
up vote
1
down vote
The reference manual of mv
clearly states how to use the --force
option.
If a destination file exists but is normally unwritable, standard
input is a terminal, and the âÂÂ-fâ or âÂÂ--forceâ option is not given, âÂÂmvâÂÂ
prompts the user for whether to replace the file. (You might own the
file, or have write permission on its directory.) If the response is
not affirmative, the file is skipped.
Moreover, the manual highlights why mv
will never replace non-empty directories.
Note: âÂÂmvâ will only replace empty directories in the destination.
Conflicting populated directories are skipped with a diagnostic.
One way is to move files and directories without deleting existing contents in the target directory.
-b, --backup[=METHOD]
Make a backup of each file that would otherwise be overwritten or removed.
All files and directories are moved without issue and nobody does not loose its data.
prompt% mv -b /foo_path/bar/* /foo_path
prompt% rmdir -v /foo_path/bar
The reference manual of mv
clearly states how to use the --force
option.
If a destination file exists but is normally unwritable, standard
input is a terminal, and the âÂÂ-fâ or âÂÂ--forceâ option is not given, âÂÂmvâÂÂ
prompts the user for whether to replace the file. (You might own the
file, or have write permission on its directory.) If the response is
not affirmative, the file is skipped.
Moreover, the manual highlights why mv
will never replace non-empty directories.
Note: âÂÂmvâ will only replace empty directories in the destination.
Conflicting populated directories are skipped with a diagnostic.
One way is to move files and directories without deleting existing contents in the target directory.
-b, --backup[=METHOD]
Make a backup of each file that would otherwise be overwritten or removed.
All files and directories are moved without issue and nobody does not loose its data.
prompt% mv -b /foo_path/bar/* /foo_path
prompt% rmdir -v /foo_path/bar
edited Jul 6 at 5:24
answered Jul 5 at 17:25
Fólkvangr
1618
1618
add a comment |Â
add a comment |Â
up vote
1
down vote
Issue at Hand
You wish to move the contents of foo/bar/
up a level to foo/
.
I will be referencing this post on superuser as well as this post from serverfault in the solution.
Solution
According to user Stephan202, you are looking for the following commands to execute this task:
cd /path/to/foo/bar
mv * .[^.]* ..
It should also be possible, from within foo/bar/
, to run the following command as well:
(shopt -s dotglob; mv -- * ..)
Verify you have the correct permissions as well. If needed run the command with root(sudo) privileges.
Conclusion
Please comment if you have any questions or issues with this answer. I highly suggest you read through each link I have provided thoroughly before attempting the commands. I appreciate feedback to correct any misconceptions and to improve my posts. I can update my answer as needed.
Best of Luck!
add a comment |Â
up vote
1
down vote
Issue at Hand
You wish to move the contents of foo/bar/
up a level to foo/
.
I will be referencing this post on superuser as well as this post from serverfault in the solution.
Solution
According to user Stephan202, you are looking for the following commands to execute this task:
cd /path/to/foo/bar
mv * .[^.]* ..
It should also be possible, from within foo/bar/
, to run the following command as well:
(shopt -s dotglob; mv -- * ..)
Verify you have the correct permissions as well. If needed run the command with root(sudo) privileges.
Conclusion
Please comment if you have any questions or issues with this answer. I highly suggest you read through each link I have provided thoroughly before attempting the commands. I appreciate feedback to correct any misconceptions and to improve my posts. I can update my answer as needed.
Best of Luck!
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Issue at Hand
You wish to move the contents of foo/bar/
up a level to foo/
.
I will be referencing this post on superuser as well as this post from serverfault in the solution.
Solution
According to user Stephan202, you are looking for the following commands to execute this task:
cd /path/to/foo/bar
mv * .[^.]* ..
It should also be possible, from within foo/bar/
, to run the following command as well:
(shopt -s dotglob; mv -- * ..)
Verify you have the correct permissions as well. If needed run the command with root(sudo) privileges.
Conclusion
Please comment if you have any questions or issues with this answer. I highly suggest you read through each link I have provided thoroughly before attempting the commands. I appreciate feedback to correct any misconceptions and to improve my posts. I can update my answer as needed.
Best of Luck!
Issue at Hand
You wish to move the contents of foo/bar/
up a level to foo/
.
I will be referencing this post on superuser as well as this post from serverfault in the solution.
Solution
According to user Stephan202, you are looking for the following commands to execute this task:
cd /path/to/foo/bar
mv * .[^.]* ..
It should also be possible, from within foo/bar/
, to run the following command as well:
(shopt -s dotglob; mv -- * ..)
Verify you have the correct permissions as well. If needed run the command with root(sudo) privileges.
Conclusion
Please comment if you have any questions or issues with this answer. I highly suggest you read through each link I have provided thoroughly before attempting the commands. I appreciate feedback to correct any misconceptions and to improve my posts. I can update my answer as needed.
Best of Luck!
edited Jul 21 at 18:40
answered Jul 5 at 11:08
kemotep
1,0721516
1,0721516
add a comment |Â
add a comment |Â
up vote
0
down vote
If you have a directory foo
that only contains a directory bar
. (bar
may contain other stuff).
And you want to rename foo/bar
â foo
, then do:
mv -T foo foo.original
mv -T foo.original/bar foo
rmdir foo.original
You can leave of the -T
if your mv
does not have this option, however it makes it safer.
add a comment |Â
up vote
0
down vote
If you have a directory foo
that only contains a directory bar
. (bar
may contain other stuff).
And you want to rename foo/bar
â foo
, then do:
mv -T foo foo.original
mv -T foo.original/bar foo
rmdir foo.original
You can leave of the -T
if your mv
does not have this option, however it makes it safer.
add a comment |Â
up vote
0
down vote
up vote
0
down vote
If you have a directory foo
that only contains a directory bar
. (bar
may contain other stuff).
And you want to rename foo/bar
â foo
, then do:
mv -T foo foo.original
mv -T foo.original/bar foo
rmdir foo.original
You can leave of the -T
if your mv
does not have this option, however it makes it safer.
If you have a directory foo
that only contains a directory bar
. (bar
may contain other stuff).
And you want to rename foo/bar
â foo
, then do:
mv -T foo foo.original
mv -T foo.original/bar foo
rmdir foo.original
You can leave of the -T
if your mv
does not have this option, however it makes it safer.
edited Jul 6 at 8:05
answered Jul 5 at 18:15
ctrl-alt-delor
8,73831947
8,73831947
add a comment |Â
add a comment |Â
up vote
-2
down vote
Simply use the move command :
cd foo
mv bar/* .
As Jeff Schaller suggest, use
shopt -s dotglob
before the mv command to move hidden files and use the option -i
of mv if you want an interactive check before overwriting
In bash, consider setting dotglob so that this picks up âÂÂhiddenâ files.
â Jeff Schaller
Jun 21 at 12:05
Note that this may overwrite files that have the same names in both folders, and that hidden files are skipped.
â Kusalananda
Jun 21 at 12:06
1
Does not work, I get `Not possible because the directory is not empty"
â Black
Jul 5 at 10:30
add a comment |Â
up vote
-2
down vote
Simply use the move command :
cd foo
mv bar/* .
As Jeff Schaller suggest, use
shopt -s dotglob
before the mv command to move hidden files and use the option -i
of mv if you want an interactive check before overwriting
In bash, consider setting dotglob so that this picks up âÂÂhiddenâ files.
â Jeff Schaller
Jun 21 at 12:05
Note that this may overwrite files that have the same names in both folders, and that hidden files are skipped.
â Kusalananda
Jun 21 at 12:06
1
Does not work, I get `Not possible because the directory is not empty"
â Black
Jul 5 at 10:30
add a comment |Â
up vote
-2
down vote
up vote
-2
down vote
Simply use the move command :
cd foo
mv bar/* .
As Jeff Schaller suggest, use
shopt -s dotglob
before the mv command to move hidden files and use the option -i
of mv if you want an interactive check before overwriting
Simply use the move command :
cd foo
mv bar/* .
As Jeff Schaller suggest, use
shopt -s dotglob
before the mv command to move hidden files and use the option -i
of mv if you want an interactive check before overwriting
edited Jun 21 at 12:14
Kusalananda
101k13199312
101k13199312
answered Jun 21 at 12:03
Jean-Paul Sabatier
224
224
In bash, consider setting dotglob so that this picks up âÂÂhiddenâ files.
â Jeff Schaller
Jun 21 at 12:05
Note that this may overwrite files that have the same names in both folders, and that hidden files are skipped.
â Kusalananda
Jun 21 at 12:06
1
Does not work, I get `Not possible because the directory is not empty"
â Black
Jul 5 at 10:30
add a comment |Â
In bash, consider setting dotglob so that this picks up âÂÂhiddenâ files.
â Jeff Schaller
Jun 21 at 12:05
Note that this may overwrite files that have the same names in both folders, and that hidden files are skipped.
â Kusalananda
Jun 21 at 12:06
1
Does not work, I get `Not possible because the directory is not empty"
â Black
Jul 5 at 10:30
In bash, consider setting dotglob so that this picks up âÂÂhiddenâ files.
â Jeff Schaller
Jun 21 at 12:05
In bash, consider setting dotglob so that this picks up âÂÂhiddenâ files.
â Jeff Schaller
Jun 21 at 12:05
Note that this may overwrite files that have the same names in both folders, and that hidden files are skipped.
â Kusalananda
Jun 21 at 12:06
Note that this may overwrite files that have the same names in both folders, and that hidden files are skipped.
â Kusalananda
Jun 21 at 12:06
1
1
Does not work, I get `Not possible because the directory is not empty"
â Black
Jul 5 at 10:30
Does not work, I get `Not possible because the directory is not empty"
â Black
Jul 5 at 10:30
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
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%2funix.stackexchange.com%2fquestions%2f451081%2fhow-to-move-content-of-a-folder-to-current-folder%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
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');
);
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');
);
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
mv
complains for reasons, in the end it depends what exactly you want to happen when there are folders and files to be overwritten... There are also some corner cases to take note of, e.g. what happens when there is abar/bar/
, or other conflicts.â frostschutz
Jul 5 at 11:02
Is there anything else in foo? (is it just bar?)
â ctrl-alt-delor
Jul 5 at 18:11
@ctrl-alt-delor, there are many other files and folders in foo
â Black
Jul 6 at 8:04
It is best to edit the question, so that people see it (not just leave amendments in the comments).
â ctrl-alt-delor
Jul 6 at 8:04