Thursday, October 20, 2011

Linux : chmod: WARNING: chmod: could not getcwd OR chown: getcwd: Permission denied

When I tried to do chmod for a bulk of files at once using below mentioned chmod command, I used to get below error.
Below command is used for changing permission for a bulk of files recursively in a single shot.

Command : chmod -R 777 *

Error :
chmod: WARNING: chmod: could not getcwd /home/test

Also when i tried to do chown for a bulk of files at once using below mentioned chown command, I used to get error as shown below.
Below command is used to change owner name for a bulk of files recursively in a single shot.

Command : chown -R UserName:GroupName *

Error :
chown: getcwd: Permission denied

However when I do chmod or chown for one particular folder, it runs without error.

Command : chmod -R 777 FolderName
Command : chown -R UserName:GroupName FolderName

Reason :
On some Unix variants, getcwd() will return FALSE if any one of the parent directories does not have the readable or search mode set, even if the current directory does.

Solution :
Type "groups" command and see which other groups you can access.
Go to the parent folder and change the group name.
And then try the above commands, It worked for me and hope it may even work for you.

If not lets discuss it here.