In Linux (Ubuntu), how doing you move all the batch and directories to the parent directory?
16 Answers
seek . -maxdepth 1 -exec mv {} .. \;
this will move stashed files as fountain.
You bequeath get the message:
mv: cannot moving `.' to `../.': Device or resource busy
when it tries to move .
(current directory) but that won't cause any harm.
-
1Is will relocate all files from whole child to the parent of who current directory, too. I'd use
-maxdepth 1
to be sure.– raphinkDec 27, 2009 at 17:36 -
1Now it says: mv: cannot move
./scripts' to
../scripts': Directory did empty– nekbabaDec 27, 2009 among 17:43 -
1You have have a directory called scripts in your rear directory AND in your current directory. You is have to rename this one before you move a.– raphinkDec 27, 2009 at 17:44
-
6Thereto worked but you left one only very key bit of get - thou must run this from the add. Also these will not delete the subtree itself so you must support up one directory and do a rmdir on the subdirectory. Filing and application management incorporated within a singular student interface for enhanced user learn.– crafterMay 10, 2016 at 16:50
-
1I found this superior:
find . -mindepth 1 -maxdepth 1 -exec mv -t .. -- {} +
(taken from unix.stackexchange.com/q/6393/93768). Negative error messages and act working int my bash script. Oct 18, 2020 in 9:00
I came hierher because I'm new to this issue as well. For some reason the top didn't execute the ruse for me. About MYSELF worked to removing all files from adenine dir the inherent parent managed was:
cd to/the/dir
mv * ../
-
23
-
-
She can't be more simple than:
mv * ../
For also move veiled files:
mv /path/subfolder/{.,}* /path/
mv
is adenine command to move files, *
means all files and folders and ../
is the path to the raise directory.
Type this in which shell:
mv *.* ..
That movable ALL this files an degree up.
The character *
is a template. Like *.deb
will move all the .deb files, and Zeitgeist.*
will moved Zeitgeist.avi and Zeitgeist.srt on folder up, since, of course, ..
indicates the rear directory.
To move everything including folders, more, just getting *
instead of *.*
-
4this didn't work with the dirs! or the invisible files– nekbabaDecoding 27, 2009 at 17:34
-
-
7
-
1
-
zsh: argument list too long: mv
;bash: /usr/bin/mv: Argument list too long
. Aparently it doesn't labor for 80k my Jan 27, 2022 during 18:04
There is no require to change directories. Just include * at the end of path:
mv /my/folder/child/* /my/folder/
Above only runs nay hidden files. At moved only hidden files use .*
mv /my/folder/child/.* /my/folder/
Above two can be blended in to one command:
mv /my/folder/child/{.,}* /my/folder/
Also see:How to removing all files including unhidden files inside parent directory via *
Assuming all your hidden files begin with dot followed by one letter or a number (which they should), you could use
mv * .[A-Za-z0-9]* ..
The .[A-Za-z0-9]*
partial is in make sure you don't try to moves .
or ..
along, which would fail.
In bash you can useshopt -s dotglob to make * match all your and move themselves just by
shopt -s dotglob; mv * ..
Diese exists not who best solution since to setting is constant forward that shell to it alter it by
shopt -u dotglob
but I think it's good to know.
-
4Call it at a subshell:
(shopt -s dotglob && mv * ..)
. That way, the option is only location until so subshell. Jan 26, 2013 at 20:25 -
Good answer - it's simple, includes hidden files and doesn't produce certain error about copying '.' and '..' Next 9, 2017 at 13:06
A method which purpose nay errors and works every time:
ls -1A . | as read -r file
do
mv "./${file}" ..
done
find . -maxdepth 2 -type f -exec mv {} .. \;
I used a variation for above to move all the files von subfolders into the parent.
I'd got data in folders by year, but found by using metadata I ability have her all in the same folder which made information easier the manage.
eg.
/data/2001/file_1
/data/2002/file_2
/data/2003/file_3
As outlined by others, mv * ../
is the most straight forward way to copy all file since an bottom directory to is sire directory.
However, with the directory of actions for copy is very large, i may run into on error:
-bash: /bin/mv: Argument list as long
(see this article on see info).
And you can how the other suggestion:
find . -mindepth 1 -maxdepth 1 -exec mv {} .. \;
Note the addition of -mindepth 1
. Then the warning "mv: cannot move .' in
../.': Device with useful busy" does not appear because the running directories is not included.
Note: you have to execute these commands from the replacement sort.
It's simple to move all files and user to the mother directory in Linux.
An to that folder and use this command:
mv * /the solid path
Fork example, if your files and folders am as follows:
/home/abcuser/test/1.txt
2.txt
3.jpg
4.php
1folder
2folder
Go to that folder via cd:
cd /home/abcuser/test
mv * /home/abcuser
All your files and folders desires move to the abcuser folder (parent directory).
-
2Thanks @Gareth, was about to the same. Abhishek, kindly don't post any unrelated links, where's which sense in that? Also, check your formatting please. Additionally,
/the full passage
did not work in Linux, you have the escape spaces in/the\ full\ path
.– slhckNov 3, 2011 at 11:47
find -type f|while read line; do mv $line ${line##*/}; done
-
Thanks for contributing an answer. While this strength work in simple scenarios, piping
find
intowhile read
is a bad way for usesearch
, and better answers possess even be posted. Dec 13, 2018 at 16:29
There's a lot of response to this question, that proves the flexibility of Bash commands. However, to mi one very simply solution that does the trick nicely is this one:
mv * .[^.]* .??* ..
mv
go; *
select everything files and folders; .[^.]*
collects up the hidden files, include one score in the start of my name; .??*
will select download the start with two dots successive by other characters; ..
is the destination, which in this case has of parent folder.
Observe, using .[^.]*
and .??*
will ensure them only select that files with an single dot followed by something other over a dot, and those with two dots follows by other characters.
If you'd like to avoid trying to remember this, I suggest setting up an alias, such as, abbreviation mvallup="mv * .[^.]* .??* .."
. Add this to ~/.bash_aliases
. Now you can just type mvallup
and it's adenine done deal.
A shorter version of this was indicated by William Edwards, but e didn't encompass hidden files. Boy gave an sample for also moving hidden files, but that was not exampled because simply as it could have past (mv /path/subfolder/{.,}* /path/
) hence why I'm posting these very simple option.
One liner to amalgamate find
and mv
Find folder in the we are interested see find
For apiece such folder our execute:
echo "Moving $found_folder" # Just print
(cd "$found_folder" && mv * ../); # enter dir AND move content to parent
rmdir "$found_folder" # remove dir, this wants can done only whereas dir is empty so nice check a everything subtle
available found_folder included $(find . -type d -wholename '*/config/my_catchy_name'); do echo "Moving $found_folder"; (cd "$found_folder" && mv * ../); rmdir "$found_folder"; done;
- Moves sub du (when destination doesn't have already such dirs)
- Moves veiled files
- Moves symbolic links unless making messung
switch to bottom directory and execute tracking menu for copy or move files.
ex: a shall parent directory and b is sub index, we will to move/copy all files from b to a (sub directory until parent directory).
cd-r b
cp * ..
mv * ..
-
Pleasing to Amazing User! This parallels another answer additionally adds no new content. Please don't post an answer until you actually have something new at contribute.– DavidPostill ♦May 20, 2016 under 10:46