su with user ID (not name)
I'm trying to delete a load of files owned by previously existing users. In other words I then need to "su [username] -c 'rm -r [dirname]' where [username] matches the owner of the files. (I don't have root access to the server but do have the ability to su to any of the users I need to delete files for.) If I use "ls -l" I see the user names truncated to 8 chars, so I'm using "ls -ln" to see the numeric user ID of the files instead. However su doesn't work with numeric UID values. So either I need to find a way to get the fullname of the owner (I know stat will do this but I have a lot these to do and I can't see a good way to just get a list), or find a way to map the UID to a name for su, or some other workaround I haven't thought of. Suggestions? -- Mark Rogers // More Solutions Ltd (Peterborough Office) // 0845 45 89 555 Registered in England (0456 0902) at 13 Clarke Rd, Milton Keynes, MK1 1LG
On 01 Feb 13:56, Mark Rogers wrote:
I'm trying to delete a load of files owned by previously existing users. In other words I then need to "su [username] -c 'rm -r [dirname]' where [username] matches the owner of the files. (I don't have root access to the server but do have the ability to su to any of the users I need to delete files for.)
If I use "ls -l" I see the user names truncated to 8 chars, so I'm using "ls -ln" to see the numeric user ID of the files instead. However su doesn't work with numeric UID values.
So, get the username... getent passwd <uid> Thanks, -- Brett Parker
Brett Parker wrote:
So, get the username...
getent passwd <uid>
That's what I was after - thanks. Seems odd that there isn't a non-truncated ls view, and that su doesn't work with a UID, though. Just discovered that although I don't have the rights to rm the files, I do have the rights to chown them, which is another (easier, now I find it!) way around... -- Mark Rogers // More Solutions Ltd (Peterborough Office) // 0845 45 89 555 Registered in England (0456 0902) at 13 Clarke Rd, Milton Keynes, MK1 1LG
On 01 Feb 14:29, Mark Rogers wrote:
Brett Parker wrote:
So, get the username...
getent passwd <uid>
That's what I was after - thanks.
Seems odd that there isn't a non-truncated ls view, and that su doesn't work with a UID, though.
I don't appear to be able to get ls to not show the full username... I find ps will truncate, but ls seems to "just work"... (I've just checked against a 13 char long username...).
Just discovered that although I don't have the rights to rm the files, I do have the rights to chown them, which is another (easier, now I find it!) way around...
Sounds "interesting", I can only assume that you own the parent directory for them. Thanks, -- Brett Parker
Brett Parker wrote:
I don't appear to be able to get ls to not show the full username... I find ps will truncate, but ls seems to "just work"... (I've just checked against a 13 char long username...).
Hmmm... This is a (heavily) modified RH install (not sure which RH, but old; RH7 probably) so maybe things have changed. Most of my own stuff uses shorter names anyway so I just assumed this was common.
Just discovered that although I don't have the rights to rm the files, I do have the rights to chown them, which is another (easier, now I find it!) way around...
Sounds "interesting", I can only assume that you own the parent directory for them.
I have no idea how it works, but basically I have an "admin" user which is supposed to give me root-like permissions without being root. In practise it's a bit hit and miss as to which things I can do, but essentially its a normal user that does have some overall control of other accounts (except root). It's a hosted virtual machine I have little control over. -- Mark Rogers // More Solutions Ltd (Peterborough Office) // 0845 45 89 555 Registered in England (0456 0902) at 13 Clarke Rd, Milton Keynes, MK1 1LG
Mark Rogers <mark@quarella.co.uk> wrote:
So either I need to find a way to get the fullname of the owner (I know stat will do this but I have a lot these to do and I can't see a good way to just get a list)
This may be dangerous:- find . -maxdepth 1 -printf 'su %u -c "rm -r %p"\n' | sh -x Hope that helps, -- MJ Ray http://mjr.towers.org.uk/email.html tel:+44-844-4437-237 - Webmaster-developer, statistician, sysadmin, online shop builder, consumer and workers co-operative member http://www.ttllp.co.uk/ - Writing on koha, debian, sat TV, Kewstoke http://mjr.towers.org.uk/
On 01 Feb 15:35, MJ Ray wrote:
Mark Rogers <mark@quarella.co.uk> wrote:
So either I need to find a way to get the fullname of the owner (I know stat will do this but I have a lot these to do and I can't see a good way to just get a list)
This may be dangerous:- find . -maxdepth 1 -printf 'su %u -c "rm -r %p"\n' | sh -x
EWWW - definately dangerous, semicolons! return characters! bad slef! naughty! -- Brett Parker
participants (3)
-
Brett Parker -
Mark Rogers -
MJ Ray