Author Topic: [solved]global command to change file owner?  (Read 472 times)

Offline yonnie

  • Full Member
  • ***
  • Posts: 92
[solved]global command to change file owner?
« on: July 26, 2012, 01:22:19 AM »
Using lxde mini 12.06.  I'm finding hundreds of files are owned by user 1000 and group 1000 on old another distro hdd.  I can't copy these to my new home directory on new hdd.  All of these files should be user 500 and group 500.

Switching from another distro 10.  Have many years worth of files that have somehow been given strange user/group ownership and can't get them off of the old drive and onto the new.

Is there a program suitable for this?  Or a global way of finding which files are wrong user and which are correct?
« Last Edit: August 13, 2012, 01:19:41 PM by yonnie »

Offline aguila

  • Hero Member
  • *****
  • Posts: 1206
  • soaring high = no Windows here :-D
Re: global command to change file owner?
« Reply #1 on: July 26, 2012, 01:40:49 AM »
Code: [Select]
su

chown -R 500:500 /dev/sdX/*

This will change every file and directory's owner and group to 500.

Verify the path to your he'd. Could be /dev/hda/ if it's an IDE drive or /media/name-of-the-drive if it's a portable hdd.

After typing "su" hit return and enter your root password.

Do at your own risk. Try a single file first.
All that is is good. PCLinuxOS is.

Thinkpad X61 Tablet, Core2Duo 1.66 MHz, 4 GB Ram, Intel onboard Graphics, Plextor PX-256M3 256 GB SSD; Thinkpad R61i, Core2Duo 1.66 MHz, 2 GB Ram, Intel onboard graphics, 120 GB HDD

Online Bald Brick

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6471
  • I'm going South
Re: global command to change file owner?
« Reply #2 on: July 26, 2012, 03:37:59 AM »
Code: [Select]
su

chown -R 500:500 /dev/sdX/*

This will change every file and directory's owner and group to 500.

Verify the path to your he'd. Could be /dev/hda/ if it's an IDE drive or /media/name-of-the-drive if it's a portable hdd.

After typing "su" hit return and enter your root password.

Do at your own risk. Try a single file first.

The command as given won't work. You'll get the error message "chown: cannot access `/dev/sdX/*': Not a directory". But
Code: [Select]
chown -R 500:500 /media/<name-of-the-partition>/* will work.

In other words, "chown" can't access devices like /dev/sda and /dev/sdb directly. The partition you want to run it on must be mounted, and after that you must specify the path to the mountpoint, not the path to the device node.
Code: [Select]
chown -R 500:500 /home/<username>/<myfiles>/*is OK. But actually you don't need the asterisk with the -R option.
Code: [Select]
chown -R 500:500 /home/<username>/<myfiles> will work as well.


« Last Edit: July 26, 2012, 03:42:05 AM by Bald Brick »
Feed the trolls!
They need it!

AMD Athlon 7450 Dual-Core Processor, 7.80 GiB RAM, Nvidia GeForce GT 120/PCIe/SSE2, OpenGL/ES-version: 3.3 0 NVIDIA 295.40, SBx00 Azalia (Intel HDA) soundcard, ‎Logitech B500 webcam, SAA7146 DVB card, HDDs: Seagate 250824AS, Western Digital WD10EAVS-00D

Offline aguila

  • Hero Member
  • *****
  • Posts: 1206
  • soaring high = no Windows here :-D
Re: global command to change file owner?
« Reply #3 on: July 26, 2012, 06:14:15 AM »
Hi Bald Brick.

Thanks for the correction. Never needed it so far, so I didn't know its limits. No asterisk needed with the -R option, good to know.

So, in one line
Code: [Select]
mount /dev/sdX /home/mymame/old-hdd && chown -R 500:500 /home/myname/old-hdd?
All that is is good. PCLinuxOS is.

Thinkpad X61 Tablet, Core2Duo 1.66 MHz, 4 GB Ram, Intel onboard Graphics, Plextor PX-256M3 256 GB SSD; Thinkpad R61i, Core2Duo 1.66 MHz, 2 GB Ram, Intel onboard graphics, 120 GB HDD

Online Bald Brick

  • PCLinuxOS Tester
  • Hero Member
  • *******
  • Posts: 6471
  • I'm going South
Re: global command to change file owner?
« Reply #4 on: July 26, 2012, 07:05:27 AM »
Hi Bald Brick.

Thanks for the correction. Never needed it so far, so I didn't know its limits. No asterisk needed with the -R option, good to know.

So, in one line
Code: [Select]
mount /dev/sdX /home/mymame/old-hdd && chown -R 500:500 /home/myname/old-hdd?

Almost. You should not try to mount the whole drive /dev/sdX; you should mount the partitions on it, /dev/sdXn. (If there's only one partition on the drive, n will be 1.)

Also note that the mountpoint has to exist before you manually can mount anything on it, so if /home/myname/old-hdd doesn't, you should create a subdirectory called old-hdd in /home/myname first:
Code: [Select]
mkdir -p /home/<username>/old-hdd
(In this case the -p option is not really necessary.)

When you let the system mount removable media or other partitions semi-automatically under /media it creates the mountpoints on the fly. When you do the mounting yourself the mountpoints have to exist before you can do it.



And then there's actually a tiny difference between
Code: [Select]
chown -R 500:500 /home/myname/old-hddand
Code: [Select]
chown -R 500:500 /home/myname/old-hdd/*
The first command will change the owner and group of the old-hdd folder and everything in it; the second will change owner and group of everything in the folder but not of the folder itself.
« Last Edit: July 26, 2012, 04:20:28 PM by Bald Brick »
Feed the trolls!
They need it!

AMD Athlon 7450 Dual-Core Processor, 7.80 GiB RAM, Nvidia GeForce GT 120/PCIe/SSE2, OpenGL/ES-version: 3.3 0 NVIDIA 295.40, SBx00 Azalia (Intel HDA) soundcard, ‎Logitech B500 webcam, SAA7146 DVB card, HDDs: Seagate 250824AS, Western Digital WD10EAVS-00D

Offline yonnie

  • Full Member
  • ***
  • Posts: 92
Re: global command to change file owner?
« Reply #5 on: July 26, 2012, 01:18:09 PM »
I used Bald Brick's command and changed 1 directory at a time.  Just the ones I want to keep.  So far so good.

Thanks!

Offline aguila

  • Hero Member
  • *****
  • Posts: 1206
  • soaring high = no Windows here :-D
Re: global command to change file owner?
« Reply #6 on: July 26, 2012, 02:58:34 PM »
Thank you Bald Brick, learned a lot today.

I'm happy it helped, yonnie
All that is is good. PCLinuxOS is.

Thinkpad X61 Tablet, Core2Duo 1.66 MHz, 4 GB Ram, Intel onboard Graphics, Plextor PX-256M3 256 GB SSD; Thinkpad R61i, Core2Duo 1.66 MHz, 2 GB Ram, Intel onboard graphics, 120 GB HDD