chmod: How to recursively add execute permissions only to files which already have execute permission [closed] - linux

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this question
I noticed:
chmod -R a+x adds execute permissions to all files, not just those who are currently executable.
Is there a way to add execute permissions only to those files who already have an execute set for the user permission?

Use find:
find . -perm /u+x -execdir chmod a+x {} \;

You can use find to get all those files:
find . -type f -perm -o+rx -print0 | xargs -0 chmod a+x
Update: add -print0 to preserve space in filenames

Related

What is the linux command to give execution permission of all files in current folder [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Closed 9 years ago.
Improve this question
Remember I need the command to change permissions of all files in current folder?
It depends on what you mean by "current" folder; if you mean the current folder (and all subfolders) then you could use find and chmod like so -
find . -type 'f' -exec chmod +x {} \;
If you mean the current folder (and no sub-folders) then you would use it like so -
find . -maxdepth 1 -type 'f' -exec chmod +x {} \;
OR you could use find (possibly with maxdepth) and xargs likes so
find . -print0 | xargs -0 chmod +x
Note that these commands will correctly handle files with spaces in the name and most other edge cases.
Use chmod with a glob:
chmod +x *
(Technically that will give permission to list directories, too, but that shouldn't be a problem.)

chmod exclusions [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
I know I should assign a group and then set an umask so that groups writable permissions persist but for whatever reason I can't do this. I need to chmod recursively a directory except one sub folder (web10), would the following work?
cd /var/www/clients/
find . -type f -not -path "*web10*" -exec chmod 777 '{}' \;
If you want to exclude files or directories, you use -prune
find /var/www/clients/ -name web10 -type d -prune -o -type f -print0 | xargs -0 chmod 0640
You should also use xargs where possible. With -exec you call the command once for every file found, whereas xargs collects as many files as possible and calls the command once for N files, resulting in a more efficient execution and better performance.

exclude directories mv unix [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
The command below moves every hidden/normal file ending with *string without . or _ before it.
mv {.,}*[!._]string /destination
How can I also exclude moving all directories in the above command?
Try
find /WHERE/TO/FIND -name '*STRING' \( ! -name '*_STRING' -o ! -name '*.STRING' \) -type f -exec mv \{\} /WHERE/TO/MOVE \;
Note, if you want to move every file from only the /WHERE/TO/FIND directory, you should add -maxdepth 1 (after e.g. the -type f part).
How about:
for file in {.,}*[!._]string; do test -f "$file" && mv "$file" /destination; done
In what shell does the [!._] glob actually work when used with {.,}? You would probably be better off avoiding the {} notation and do:
for file in .*[!._]string *[!._]string; do ... ; done

linux command to empty all files of a directory [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I´d like to empty all files from a directory. I´d tried this:
find myFolderPath/* -exec cat /dev/null > {} ';'
but it does not work. How can I do it?
You can't use redirection (>) within find -exec directly because it happens before the command runs and creates a file called {}. To get around this you need to do it in a new shell by using sh -c.
Also, note that you don't need to cat /dev/null > file in order to clobber a file. You can simply use > file.
Try this:
find . -type f -exec sh -c '>"{}"' \;
This will do what you want:
for f in *; do >$f; done

Setting file permission for Files and Directories [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 6 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
I need to apply below permission policies to my files under www folder
664 to all files in www recursively,
755 to all directories under www recursively
I tried
find . -type f -exec chmod 644 {} ;
find . -type d -exec chmod 755 {} ;
But always getting error
find: missing argument to `-exec'
What is the solution?
Backslash before semi-colon (or quotes around it):
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;
The shell sees the semi-colon you typed as the end of the command and does not pass it to find, which then complains that it is missing.
Use backslash before ';'
find . -type f -exec chmod 644 {} \;

Resources