[SOLVED] Move contents of subfolder into parent folder

I've made a mistake with the mv command...I tried to move my music from one user to another using

sudo mv /home/{user1}/Music /home/{user2}/Music

which seemed like it would do the job. But what it actually did was create a folder inside /home/{user2}/Music called Music with all the music in. Like this

$ sudo ls /home/{user2}/Music
Music

So I tried to get the contents of /home/{user2}/Music/Music into /home/{user2}/Music/Music. But noting I try seems to work

sudo mv /home/{user2}/Music/Music/ /home/{user2}/Music

mv: '/home/{user2}/Music/Music/' and '/home/{user2}/Music/Music' are the same file
sudo mv /home/{user2}/Music/Music/* /home/{user2}/Music/
mv: cannot stat '/home/{user2}/Music/Music/*': No such file or directory

sudo mv /home/{user2}/Music/Music/ /home/{user2}/Music/
mv: '/home/{user2}/Music/Music/' and '/home/{user2}/Music/Music' are the same file
sudo mv /home/{user2}/Music/Music/ /home/{user2}/Music
mv: '/home/{user2}/Music/Music/' and '/home/{user2}/Music/Music' are the same file
sudo mv /home/{user2}/Music/Music/ /home/{user2}/
mv: cannot move '/home/{user2}/Music/Music/' to '/home/{user2}/Music': Directory not empty

I feel like I've tried every combination of trailing / and * but nothing seems to work.

I found this on Google but I've tried that option (/* on source and / on destination) in my second attempt above, it didn't work.

What is the correct mv syntax to get the contents of a subdirectory into its parent directory?

Something like this would do it (-i is interactive - ask before overwrite)

mv -i  /folder1/folder2/* /folder1

That gives me

sudo mv -i /home/{user2}/Music/Music/* /home/{user2}/Music
mv: cannot stat '/home/household/Music/Music/*': No such file or directory

But there clearly is such a directory because

$ sudo ls /home/{user2}/Music
Music

I won't subject you all to my somewhat idiosyncratic music collection, but I've also done a full ls and all the music is definitely in /home/{user2}/Music/Music

Why using sudo to copy/move files/folders from one user to another ?
My point is, if you want to copy TO user2 from user1, then work from user2 session.

1 Like

I'm in {user1} (who has sudo rights). If I do it from {user2} I have to first give them permissions over the directory where it is, so I just thought doing it as sudo would save on one operation (the permission giving), plus {user1} is me, so I can do the whole thing from the account I'm used to.

Does sudo mv not work for some reason?

Even if the second one exists, it doesn't mean that the first one exists?

Essentially it says "You are trying to move something that does not exist."

Which translated mean that the second Music folder does not exist or has no content.

ls /home/household/Music | grep "Music"

mv /path/to/subdir/* /path/to/

or

cd /path/to/subdir
mv * ../
$ sudo ls /home/{user2}/Music
Music

Doesn't that mean that in the directory 'Music' there is a sub-directory 'Music'?

sudo ls -l /home/{user2}/Music/Music                        
total 39068

...followed by a long list of all my music folders

Sorry, I can't see the difference between that and what I did second...

sudo mv /home/{user2}/Music/Music/* /home/{user2}/Music/
mv: cannot stat '/home/{user2}/Music/Music/*': No such file or directory

I'm obviously missing something, but I can't see what it is.

Have you tried this

sudo mv /home/{user2}/Music/Music /home/{user2}/

Yes.

I got it to work eventually by changing the ownership to {user2} (which was going to need doing anyway, obviously) and the logging on as {user2} them using

mv /home/{user2}/Music/Music/* /home/{user2}/Music/

It worked perfectly.

I still have no idea why sudo mv moved the files in the first place (from /home/{user1}/Music to /home/{user2}/Music), but then wouldn't move them any further once there. I thought sudo was supposed to be invincible!

Still all done now. Thanks to all.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.