How to move all files and folders via mv command
Solution 1
Try with this:
mv /path/sourcefolder/* /path/destinationfolder/
Solution 2
zsh:
mv /src/*(D) /dst/
(D)
to include dot-files.
Solution 3
This works for me in Bash (I think this depends on your shell quite a bit...)
$ mv source/{,.}* /destination/folder/here
Solution 4
This works for me in Bash 4.2.46, it moves all files and folders including hidden files and folders to another directory
mv /sourcedir/{,.[^.]}* /destdir/
Notice that .[^.]* means all hidden files except . and ..
Solution 5
I'd say it's a bit boring, but really bullet-proof (GNU) way is:
cd /SourceDir && find ./ -maxdepth 1 -mindepth 1 -exec mv -t /Target/Dir {} +
P. S. Now you can possibly see why lots of people do prefer Midnight Commander, though.
Related videos on Youtube
Luka
My name is Luka, I am student of Business economics at John Naisbitt University. And I am Linux System Administrator, PHP, jQuery (JavaScript) developer. Love technology and new things, always learning. Currently running a web hosting company in Serbia Leo Host.
Updated on September 18, 2022Comments
-
Luka over 1 year
How can I move all files and folders from one directory to another via mv command?
-
Ben Lessani over 11 yearsThis wouldn't include any "hidden" files (eg.
.htaccess
) -
chutz over 11 yearsGood point. If you are using bash, then you can run
shopt -s dotglob
and then "*" will match hidden files, too. -
poige over 11 yearsActually, it shouldn't since in Bash
source/{,.}*
matches dir-entries named./
and../
-
Silvio Silva over 11 yearsWhen I try I get
mv: overwrite 'destination/.'? mv: overwrite 'destination/..'?
, but adding-n
tomv
stops it from trying to overwrite -
Jensen010 over 11 years@Putnik - that's a good gotcha! what os/distro ? ( I was working on OSX when I was messing around with this...)
-
Stéphane Chazelas over 8 years
ls -Q
doesn't output in a format that is suitable to use witheval
or even$(...)
. Try after having runtouch '$(reboot)'
for instance (ortouch '$(uname)'
for a milder version). -
Stéphane Chazelas over 8 years
-A
is now POSIX (since POSIX.1-2008). -
user1063287 almost 8 yearsWhat happens if there are folders and files with the same name in the destination folder? Are they overwritten?
-
user1063287 almost 8 years... it seems folders with the same name are not overwritten.
mv: cannot move '/a/js' to '/b/js': Directory not empty
-
Stéphane Chazelas over 7 years
.[^.]*
(or its POSIX equivalent.[!.]*
) also excludes..anything
files. -
Jaime M. about 6 yearsIt works in
tcsh
too. -
Pathros almost 6 yearsSyntax error on (D) Why??
-
Stéphane Chazelas almost 6 years@Pathros, probably because you'd not doing doing it in
zsh
. -
Luka almost 6 yearsYou just pass
-f
to it to overwrite -
Luka almost 6 yearsI know I accepted the first answer many years ago, and it's stupid for me now to change it. But actually, I've been always using this method.
-
DJCrashdummy over 5 yearsunix.stackexchange.com/a/402856/93768 contains the full correct expression.
-
trainoasis over 5 years@Luka actually -f doesn't help with overwriting folders. Says the same thing. You gotta use rsync or make sure folders are empty
-
Luka over 5 yearsIt does help if you use
/bin/mv -f
instead ofmv -f
. Becausemv
is by default aliased to-i
on some distributions. And that's why it appears it doesn't work. Add thisalias cp='cp'
to~/.bash_aliases
to fix it. -
Luka over 5 years@trainoasis so sorry, not
-f
, you should use-r
. But the same applies to alias if it's aliased it won't work properly. -
Thomas Weller about 5 yearsIt says "directory not empty" in for my
.git
folder -
Gal Bracha over 4 yearsTo move the current dir content - mv ./* ../another_folder