176

How can I move all files and folders from one directory to another via mv command?

Luka
  • 2,117

7 Answers7

204

Try with this:

mv /path/sourcefolder/* /path/destinationfolder/
mulaz
  • 2,517
  • 49
    This wouldn't include any "hidden" files (eg. .htaccess) – Ben Lessani Oct 05 '12 at 12:53
  • 27
    Good point. If you are using bash, then you can run shopt -s dotglob and then "*" will match hidden files, too. – chutz Oct 05 '12 at 14:52
  • 2
    What happens if there are folders and files with the same name in the destination folder? Are they overwritten? – user1063287 Jun 14 '16 at 01:08
  • 3
    ... it seems folders with the same name are not overwritten. mv: cannot move '/a/js' to '/b/js': Directory not empty – user1063287 Jun 14 '16 at 01:29
  • 2
    You just pass -f to it to overwrite – Luka Jul 20 '18 at 11:22
  • @Luka actually -f doesn't help with overwriting folders. Says the same thing. You gotta use rsync or make sure folders are empty – trainoasis Nov 25 '18 at 22:00
  • It does help if you use /bin/mv -f instead of mv -f. Because mv is by default aliased to -i on some distributions. And that's why it appears it doesn't work. Add this alias cp='cp' to ~/.bash_aliases to fix it. – Luka Nov 26 '18 at 16:19
  • @trainoasis so sorry, not -f, you should use -r. But the same applies to alias if it's aliased it won't work properly. – Luka Nov 28 '18 at 19:38
  • 1
    To move the current dir content - mv ./* ../another_folder – Gal Bracha Nov 21 '19 at 14:10
39

zsh:

mv /src/*(D) /dst/

(D) to include dot-files.

21

This works for me in Bash (I think this depends on your shell quite a bit...)

$  mv source/{,.}* /destination/folder/here
10

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 ..

Jun
  • 101
  • 1
  • 3
3

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.

poige
  • 6,231
-1

If you only want to do a cut and paste-like action there is a simple way that worked for me:

$mv /media/dir_source $HOME/Documents/ 

It will move the folder named dir_source located in /media to the directory $HOME/Documents/

-2

yet another way just for the heck of it (because I love convoluted ways to do things I guess)

cd /source
for f in $(\ls -QA); do eval mv $f /destination/$f; done

the -Q and the -A are not POSIX, however the -A is fairly prevalent, and to not use the -Q you need to change the IFS (which then means you don't need the eval but need to quote the variable)

IFS="
" && for f in $(ls -A); do mv "$f" /destination/"$f"; done
Drake Clarris
  • 886
  • 4
  • 7