I want to move a file in ./dir1/subdir1 to /dir2, such that the end result is the existence of a directory /dir2/dir1/subdir1 containing the files previously contained in subdir1.

I want to do this for all files found using a find command so it is important that the command takes input of the form movecommand ./dir1/subdir1 /dir2/, i.e. that I don't have to repeat the inner structure for the second argument.

Is there a good way to do this?

1 Answer 1


mv will copy the "last" object in your destination. In your case you can create the destination directory first, then move your files

mkdir /dir2/dir1/
mv /dir1/subdir/ /dir2/dir1/

or use rsync to copy and delete the source then

rsync -av dir1 dir2/
sending incremental file list

rm -r dir1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .