Web Hosting Talk







View Full Version : Different SSH Command To Move Directories! Please Help!!!


FredTT
08-13-2003, 09:26 PM
Say I want to move the folder /mnt/home2/hello to /home/. What command would be the easiest? I know there is the

cp -r /mnt/home2/hello /home/

But then I have to confirm to many over rights. I found one the other day (can't find it anymore) that tarred it up moved the tar and untarred it. It only asked once for over right (over right all). Any one know any easier commands?

JackMitchell
08-13-2003, 09:41 PM
Only thing I can think of is: cp -r

But like you said it requires all the rights stuff.. im interested in this other command also :)

fog
08-13-2003, 09:44 PM
If you want to move and not copy:

mkdir /home/hello # make /home/hello
mv /mnt/home2/hello /home/hello # move it

EDIT: Assume you know this, but better safe than sorry -- the # is a comment; don't type the # or anything after it. (You can do it just fine, it's just a waste of time to re-type.)

JackMitchell
08-13-2003, 09:46 PM
oh.. so that ones fully moves it and leaves nothing behind? If so, thanks heaps, needed that one for ages :D

Slidey
08-14-2003, 03:56 AM
lol

wKkaY
08-14-2003, 06:11 AM
right :) btw, if you want cp to stop questioning you about overwriting the files , use cp -fr /mnt/home2/hello /home/

rsync -a /mnt/home2/hello /home should work too .

FredTT
08-14-2003, 07:29 AM
Lol, now you tell me. To late. I already moved them all.

Protollix
08-14-2003, 09:47 AM
actually, if you are using a redhat system appending the -f to the command line may not remove the prompting as Redhat likes to alias a lot of the common commands. I know the rm command is this way, but I cannot recall if cp is as well.

In any case, by using a direct path to the binary and appending -f to it, you can surely remove the prompts (ie: /bin/cp -rf <file_to_copy> <destination>)

As well, you don't have to create the directory before you move it. In the example given above you could just do:
mv /mnt/home2/hello /home

Cheers :)

Erck121
08-15-2003, 12:42 AM
if you want to keep the same permissions on the directory when you copy it you might want to use the -p also
cp -rp
or
cp -rfp

but if you don't want to have two copies of the folder on your server then use the "mv" command.

You could also remove the -
alias cp='cp -i'

line from your .bashrc file located in the home directory of every user.

sunckell
08-15-2003, 07:47 PM
Depending on the size of the directory you are dealing with, there may be better alternatives than cp and mv. Since you have a home2 in the /mnt directory I am going to assume that the files in here are from a different partition. ( since normally you would mount additional drives and what not in this directory.)

You can use the tar command for better performance.

tar cpf - /mnt/home2/hello | tar -C /home -xpf -

This will tar the directory to STDOUT. Very helpful if there are many directories that you want to copy from one partition to another..

for example:

[root@host root]# cd /mnt/home2
[root@host root]# for i in *
> do
> echo $i
> tar cpf - $i/ | tar -C /home -xpf -
> done

That will move every directory to home from home2. ( With a lot less IO overhead than cp or mv)

Another command you can use is cpio

cd /mnt/home2; find ./hello |cpio -pdumv /home

Hope that helps...for future reference...... ;^)