changing permissions of files in a directory recursively - linux

I am trying to change the permissions of a files present in a directory and subdirectories using the below command and running into below error..can anyone help?
user#machine:/local/mnt/workspace$ find . -type f -exec chmod 644 {} \;
chmod: changing permissions of `./halimpl/ncihal/adaptation/NonVolatileStore.cpp': Operation not permitted

you can run the following command:
#chown -R directory_path
But it will change the permissions of directories also.
For only files, you can run.
#find directory_path -type f -exec chmod 644 {} \;
It also looks like you dont have enough permissions. try
#sudo find directory_path -type f -exec chmod 644 {} \;
or run the command as root user.

It looks to me like you don't have permission to change NonVolatileStore.cpp.
Are you aware of chmod's -R switch that recursively changes permissions?

if you have the root privilege, try:
sudo find . -type f -exec chmod 644 {} \;

It could be that you simply don't own that file. Run an ls -l on it to see full permissions and who the owner is.
It could also be the filesystem is read only.

Related

Setting multiple file permissions at once using ssh ( recursive folder/file permission )

I am working with digital ocean and WordPress. I have uploaded my theme and my file permissions are all wrong. I know how to set the file permissions individually using ssh but I'm wondering if I can do multiple at once rather than doing each individually. I want to set all folders inside my theme to 755 and all files to 644 (correct me if this is wrong)
Here's what I have done so far; I navigated to my theme folder using ssh then used to following command to set file permissions;
chmod 644 file.php
chmod 755 folder
chmod -R 755 will set these permissions to all files and subfolders in the tree. To set the directories to 755 and either leave the files alone or set them to 644. For this, you can use the find command. For example:
To change all the directories to 755 (drwxr-xr-x):
find /opt/lampp/htdocs -type d -exec chmod 755 {} \;
To change all the files to 644 (-rw-r--r--):
find /opt/lampp/htdocs -type f -exec chmod 644 {} \;
Please try below command for directory
find /var/www/html/ -type d -exec chmod 755 {} \;
Below command is for files permission
find /var/www/html/ -type f -exec chmod 644 {} \;

How to change specific file permissions using udev rule?

I'm trying to let my user bob the permissions to change the screen brightness, which means: let bob read, write permissions for /sys/class/backlight/intel_backlight/brightness
using:
udevadm info -a -p /sys/class/backlight/intel_backlight/
shows that following result:
looking at device '/devices/pci0000:00/0000:00:02.0/drm/card1/card1-eDP-1/intel_backlight':
KERNEL=="intel_backlight"
SUBSYSTEM=="backlight"
DRIVER==""
ATTR{actual_brightness}=="7500"
ATTR{bl_power}=="0"
ATTR{brightness}=="7500"
ATTR{max_brightness}=="7500"
ATTR{type}=="raw"
.
.
.
So I wrote a udev rule for that in /etc/udev/rules.d/30-brightness.rules
30-brightness.rules
KERNEL=="intel_backlight", SUBSYSTEM=="backlight", RUN+="/usr/bin/find /sys/class/backlight/intel_backlight/ -type f -name brightness -exec chown bob:bob {} \; -exec chmod 666 {} \;"
But event after a reboot the file permissions stays -rw-r--r-- 1 root root
So my question is how to change specific file permissions using udev rule and what am I doing wrong?
I have solved the problem,
the dev-rule should look like this (without the backslashes)
KERNEL=="intel_backlight", SUBSYSTEM=="backlight", RUN+="/usr/bin/find /sys/class/backlight/intel_backlight/ -type f -name brightness -exec chown bob:bob {} ; -exec chmod 666 {} ;"
But note that the above RUN command won't work on the terminal command line (for that you need to have the backslashes)

Changing permission of files on searching a directory

I am trying to search all directories with name 'bin' and change the permission of files under all directories which were successfully found. I tried with the below command:
find -type d -name bin -exec chmod 777 {} \;
But this changed the permission of bin directory. It did not change the permission of the files underlying bin. Please help.
Recursively changing the permission with -R as shown in the solution below is the key. Not the solution provided in the similar question.
Your approach was slightly unsuccessful.
Since your bin directory contains another files and directories, you've to change their permission recursively.
$ find -type d -name bin -exec chmod -R 777 {} \;
I Hope, this is what you've expected in return.

Permission to parent and child folders in ubuntu

I'm new to Ubuntu. Giving permission to folder using the following command in Terminal.
chmod -R 777 /var/www/html/
This command is working for html folder only. But, I have many sub folders in html folder.
How can i give 777 permissions to all the sub folders at a time?
I think you really want to do is set the directories to 755 and either leave the files alone or set them to 777. For this, you can use the find command. For example:
To change all the directories to 755 (-rwxr-xr-x):
find /var/www/html/ -type d -exec chmod 755 {} \;
To change all the files to 777 :
find /var/www/html/ -type f -exec chmod 777 {} \;
Hope this helps you.

Bash - Recursively change ownership of only the directories which belong to a certain user/group

I have a directory (we will call /files) with ~1300 subdirectories, each of which contains further subdirectories and files.
90% of the top level directories in /files belong to apache:apache and the rest belong to root:root. I need everything to belong to apache:apache.
I think if I do a recursive chown on the whole lot it will be quite extreme, so I was wondering if there's a more efficient way to recursively change ownership of just the root:root directories to apache:apache.
Bonus if chmod can be done on these directories in the same way.
Your recursive chown would have probably been done already, but you could use this instead:
find . -type d \( ! -user apache -o ! -group apache \) -print0 | xargs -0 chown apache:apache
To change directories that have the wrong permission:
find . -type d ! -perm 755 -print0 | xargs -0 chmod 755
Using linux's find command is going to help there:
find /files -user root -group root -type d \
-exec chmod something {} \; -exec chown apache.apache {} \;
for more details on WHY that works there is http://www.explainshell.com/explain?cmd=find+%2Ffiles+-user+root+-group+root+-type+d+-exec+foo+\%3B

Resources