-   Linux - Desktop (
-   -   How do I move files using mv and change ownership at the same time? (

NuxIT 03-17-2013 12:29 PM

How do I move files using mv and change ownership at the same time?
I had an issue where my top and bottom menu panels were not loading correctly on my ubuntu XFC desktop. So, I created a new user to get the panel back to normal.
Now I'm in the process of moving all my folders from user1 to the new user2's home directory.

So, this is what I've been doing.. Can someone tell me the more efficient way to go about doing this?

I'm moving one folder at a time from the terminal with the following command.


sudo mv -f /home/user1/linux /home/user2/linux
Then I change the ownership of files so I can write to them via this command.

sudo chown -hR user2 /home/user2/linux/
Now I can write to the files but I think they still retained my user1 Group settings.

user@brits:~/linux$ ll
total 80
drwxrwxr-x  2 user2 user1  4096 Mar  9 10:49 ./
-rw-rw-r--  1 user2 user1  595 Oct 10 22:58 cachefolders_size
-rw-rw-r--  1 user2 user1  398 May  6  2012 crashreport
-rw-rw-r--  1 user2 user1  551 Dec 15  2011 howto
-rw-rw-r--  1 user2 user1    40 Nov  9  2011 linuxapps

Can someone advise me if I can use one command to move the folders and subfolders while changing permissions from user1 to user2?

I'm sure I could probably use one command to move all my files and folders from user1 to user2 home directory so appreciate any help.

Also, any tip on deleting user1 and all the .cache folders ,etc associated with user1 would be helpful. I was thinking it *should* delete all the folders if I go into this menu.. System> Users and groups and delete the user1 account. I was concerned that if I delete this user1 that it might mess up the group associations I listed above??


Edit, I figured out how to change the group on all my files as well using the chgrp command. Still looking for tips to be more efficient in the future.

bigrigdriver 03-17-2013 12:52 PM

For the mv command, try this:

sudo mv /home/user1/* -tu /home/user2/
-t move all SOURCE arguments into DIRECTORY
-u move only when the SOURCE file is newer than the destination file or when the destination file is missing

That should move the entire contents of /home/user1 to /home/user2.

For the chown command, try this:

sudo chown -R user2:group /home/user2/
Use the appropriate user and group names.

NuxIT 03-18-2013 12:47 AM

Cool. Thanks for these tips bigrigdriver.. I'm going to try the mv arguments you provided when I get home this morning and see how that works out. Nice sig file.

All times are GMT -5. The time now is 02:39 PM.