Changing file/directory owner

Hi ,
I want to change owner of files or folder from 23186 to dsadm,

Present
-------

-rw-r--r-- 1 23186 gdstage 10240 Oct 31 2007 BLTRS
drwxrwxrwx 3 23186 gdstage 512 Sep 1 2010 sql

Required as
-----------

-rw-r--r-- 1 dsadm gdstage 10240 Oct 31 2007 BLTRS
drwxrwxrwx 3 dsadm gdstage 512 Sep 1 2010 sql

please provide the syntax to change one file or folder owner from one user to another user.
Thanks in advance for all your support.

chown file1(gdstage) file2(dsadm)

@coolboys. That syntax is incorrect
@sridhardw. See man chmod

man chown even.

:smiley: Hehe

For multiple files:

find . -user 23136 -print | while read filename
do
        # Before
        ls -lad "${filename}"
        # Remove echo when tested
        echo chown dsadm "${filename}"
        # After
        ls -lad "${filename}"
done

When using "find -user" and "chown", you have to beware of symlinks. The find will find symlinks owned by that user, but chown will change the ownership of the file pointed to, not the symlink itself. When fixing up file ownerships like this, it's better to use chown -h

find . -user 23136 -exec chown -h dsadm {} \;
1 Like