How to move all files and folders via mv command

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

  • mulaz

    mulaz Correct answer

    8 years ago

    Try with this:

    mv /path/sourcefolder/* /path/destinationfolder/
    

    This wouldn't include any "hidden" files (eg. `.htaccess`)

    Good point. If you are using bash, then you can run `shopt -s dotglob` and then "*" will match hidden files, too.

    What happens if there are folders and files with the same name in the destination folder? Are they overwritten?

    ... it seems folders with the same name are not overwritten. `mv: cannot move '/a/js' to '/b/js': Directory not empty`

    You just pass `-f` to it to overwrite

    @Luka actually -f doesn't help with overwriting folders. Says the same thing. You gotta use rsync or make sure folders are empty

    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.

    @trainoasis so sorry, not `-f`, you should use `-r`. But the same applies to alias if it's aliased it won't work properly.

    To move the current dir content - **mv ./* ../another_folder**

License under CC-BY-SA with attribution


Content dated before 6/26/2020 9:53 AM