Link to home
Start Free TrialLog in
Avatar of ainselyb
ainselyb

asked on

changing ownership of all files in the current directory and change the permissions so that the owner has read-write access, while group and other users have only read access.

Problem = Give commands for changing ownership of all files in the current directory to user and group nobody, and change the permissions so that the owner has read-write access, while group and other users have only read access.

I am little confused on how I can do this? I thought that in order to change the permissions on all the files in the directory, I would have to use the -R option?

Can anyone assist?
ASKER CERTIFIED SOLUTION
Avatar of omarfarid
omarfarid
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ainselyb
ainselyb

ASKER

So by changing the permissions on the directory it will effectively change the permission on all the files it contains as well?
No ..the -R switch does that

       -R, --recursive
              change files and directories recursively

Example
#create dir
mkdir dir
#create file in dir
touch dir/testFile
#change file to 777
chmod 777 dir/TestFile
#change dir to 666
chmod 666 dir

#dir is 666
root@alinux-laptop:~# ls -l | grep dir
drw-rw-rw- 2 root root  4096 2008-02-10 21:38 dir

#file is still 777 because -R was not used
root@alinux-laptop:~# ls -l dir/testFile
-rwxrwxrwx 1 root root 0 2008-02-10 21:38 dir/testFile

That would change the directory also. To change all file in directory You could use:

chown nobody:nobody /dirname/*
chmod 644 /dirname/*
No, the -R option means apply to files and subdirectories
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Using

chmod -R 644 /dirname

is not a good idea if there are any subdirectories and it effectively renders the permissions on the sub-directories as unusable.