Setting file permission for Files and Directories [closed] - linux

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 {} \;

Related

Copy files from one folder to another folder with filters [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 2 years ago.
Improve this question
I have these files in my source folder
source_path/date=20191230/somefile.txt
source_path/date=20191231/somefile.txt
source_path/date=20200101/somefile.txt
source_path/date=20200102/somefile.txt
If I do the bellow command all files will be copied to my dest_path folder
cp --recursive source_path/ dest_path/
I just want to copy all folders where dates are in 2020 or something
I just need these to files of 2020
source_path/date=20200101/somefile.txt
source_path/date=20200102/somefile.txt
How can I add filters with cp command
This question is not suitable for Stack Overflow, but this is the answer:
cp --recursive source_path/date=20200* dest_path/
Or does dest_path not exist? Then you would write
mkdir -p dest_path && cp --recursive source_path/date=20200* dest_path/
You can use find with the -name, -type and -exec flags and so if the source directory was /home/foo and the destination directory /tmp:
find /home/foo -type d -name "*date-2020*" -exec cp '{}' /tmp \;
-type signifies that we only searching directories, -name is the name we are searching for and exec for command we are executing with the results

No such file or directory find command on linux [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 6 years ago.
Improve this question
I've created script which delete old backup file from directory but this command was worked fine before 1 week and Nothing change on script or packages but still getting below error:
root#:# find /var/backups/abc/* -type d -mtime +6
/var/backups/abc/2016-03-09_0321
root#:~# find /var/backups/abc/* -type d -mtime +6 -exec rm -rf {} \;
find: `/var/backups/abc/2016-03-08_0321': No such file or directory
Problem is that, this script run every day on cron, I getting a mail like " find: `/var/backups/abc/2016-03-08_0321': No such file or directory". files are deleted but such a mails are getting from root.
find /var/backups/abc/* -type d -mtime +6 -prune -exec rm -rf {} \;
Here, we useĀ -pruneĀ on the directories that we're about to delete, so find will then not try to read their contents.
This is because of after having returned your directory, find will try to look in it (to continue his recursive search), and will fail because of you just removed it.

linux pipe argument list too long [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 8 years ago.
Improve this question
I use the following bash script to remove files older than $days.
find /home/xxx/conf_* -maxdepth 0 -mindepth 0 -type d -ctime +5 -exec rm -rf {} \;
However if the files are more than 32000+, I get
/usr/bin/find: Argument list too long
how do I trim the list down to like 20000 only?
From comment to answer:
Your problem is the glob expansion but you are already using a tool that can perfectly well handle an arbitrary number of found results, namely find. As such you should use a glob at all. Instead you should let find do all the work.
Something like:
find /home/xxx -maxdepth 1 -name 'conf_*' -type d -ctime +5 -exec rm -rf {} \;
Also if your find has -exec \+ you should probably use this instead:
find /home/xxx -maxdepth 1 -name 'conf_*' -type d -ctime +5 -exec rm -rf {} \+
For such a large number of matching directories I imagine the significantly reduced amount of executions of rm might be significantly more efficient.

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.

Resources