185

I need to move my folder with many subfolders to another path.

I'm using putty and this is what I tried: MV -r fromflderpath tofolderpath

What am I doing wrong?

1
  • 14
    I presume you are entering the command 'mv' and NOT 'MV'.
    – mdpc
    Oct 31, 2012 at 17:59

6 Answers 6

277

The mv command doesn't have an -R flag, it moves folders recursively:

sudo mv fromPath/ toPath/

Edit

If you want a file not to be replaced, use the -i for being prompted in case a file with the same name exists.

4
  • :I've a file,i've to move this to another directory but in this directory,i've a file with same name.what is the command to move it ,if i move,will i get replaced.
    – ram
    Oct 31, 2012 at 17:52
  • 4
    am I missing something here? mv moves a folder and all its contents without any flags. no cp -r;rm -r needed Oct 31, 2012 at 18:16
  • sorry, my bad. :) Oct 31, 2012 at 18:23
  • I barely remember needing to use sudo...
    – Honey
    Jan 1, 2021 at 20:43
42

For those trying to move folder, on Ubuntu using Putty, just use the following command:

sudo mv /fromPath/ /toPath/

for example:

sudo mv /root/folder1 /home/folder2/

"/" in the end means you are going to move folder1 inside folder2

If you don't, you will get "no such file or directory"

2
  • 5
    "/" in the end means you are going to move folder1 inside folder2 <- Pure gold thanks! Sep 21, 2020 at 18:34
  • I tested on Ubuntu 20.04, and found that we don't need the / at the end. with or without /, the results are the same: move folder1 to the inside of folder2. But anyways, it's good practice to put the trailing / at the end, just in case of some mistakes.(check this out).
    – starriet
    Feb 20, 2022 at 3:44
15

This worked for me:

mv src_folder target_folder/src_folder

i.e. not mv src_folder target_folder/

1
  • worked for me on macOS
    – Gi0rgi0s
    Apr 3, 2020 at 19:55
3

If it's hard to use pure shell commands, then you can install Midnight Commander, console application that makes it easier:

$ sudo apt-get install mc

Midnight Commander Screenshot

In Midnight Commander to move folder or file from one panel to another is F6, copy F5.

$ mc

If you need root access

$ sudo mc

If you want to have a mouse support

$ sudo apt-get install gpm
0

If you want to empty fromflderpath without renaming it, stand in the folder and use

mv * ../tofolderpath/
0

sudo mv source_folder/* target_folder/

and if you have like:

source_folder/file.ext
source_folder/bin/image.jpg
source_folder/etra/info.text

all of them will be moved under target_folder like:

target_folder/file.ext
target_folder/bin/image.jpg
target_folder/etra/info.text

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.