Find only files/directories with different permissions/owners


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find only files/directories with different permissions/owners
# 1  
Old 05-11-2013
RedHat Find only files/directories with different permissions/owners

My git post-update has the following lines in it to make sure the permissions are set right:

Code:
find /usr/local/apache/htdocs -type d -print0 | xargs -0 chmod 755
find /usr/local/apache/htdocs -type f -print0 | xargs -0 chmod 644
chown -R apache:apache /usr/local/apache/htdocs

The only problem is that each git update takes some time as it chmod's each and every file on the web server. So I'm assuming the fastest thing would be to only chmod only the files that have different permissions and only chown the files that aren't apache:apache.

How would I rewrite the three lines above to make that change? Many thanks.
# 2  
Old 05-11-2013
Quote:
Originally Posted by dheian
My git post-update has the following lines in it to make sure the permissions are set right:

Code:
find /usr/local/apache/htdocs -type d -print0 | xargs -0 chmod 755
find /usr/local/apache/htdocs -type f -print0 | xargs -0 chmod 644
chown -R apache:apache /usr/local/apache/htdocs

The only problem is that each git update takes some time as it chmod's each and every file on the web server. So I'm assuming the fastest thing would be to only chmod only the files that have different permissions and only chown the files that aren't apache:apache.

How would I rewrite the three lines above to make that change? Many thanks.
for first two lines try below to chnage only permissions of the other than 644(for files) and 755 for directories

Code:
find /usr/local/apache/htdocs \! -perm 644 -type f  -print0 | xargs -0 chmod 644
find /usr/local/apache/htdocs \! -perm 755 -type d -print0 | xargs -0 chmod 755


Last edited by zozoo; 05-11-2013 at 03:59 PM..
# 3  
Old 05-11-2013
I'll give that a try. Digging further, will this work for the chown?

find /usr/local/apache/htdocs \! -user apache -print0 | xargs -0 chown apache:apache

---------- Post updated at 03:10 PM ---------- Previous update was at 03:08 PM ----------

Getting an error on the command:

Code:
 find /usr/local/apache/htdocs \! -perm 644 -type f  -print0 | xargs -0 chmod 644
chmod: missing operand after `644'

# 4  
Old 05-11-2013
Quote:
Originally Posted by dheian
I'll give that a try. Digging further, will this work for the chown?

find /usr/local/apache/htdocs \! -user apache -print0 | xargs -0 chown apache:apache

---------- Post updated at 03:10 PM ---------- Previous update was at 03:08 PM ----------

Getting an error on the command:

Code:
 find /usr/local/apache/htdocs \! -perm 644 -type f  -print0 | xargs -0 chmod 644
chmod: missing operand after `644'


try this
Code:
find /usr/local/apache/htdocs \! -perm 644 -type f | xargs chmod 644

it worked for me in sloaris , which os are you using

Last edited by zozoo; 05-11-2013 at 04:46 PM..
# 5  
Old 05-11-2013
In one pass without xargs (tested with an old GNU find):
Code:
find /usr/local/apache/htdocs    \
\( -user apache -group apache -o -exec chown apache:apache {} + \)    \
\( -type d ! -perm 755 -exec chmod 755 {} + -o -type f ! -perm 644 -exec chmod 644 {} + \)

Regards,
Alister
These 2 Users Gave Thanks to alister For This Post:
# 6  
Old 05-12-2013
Quote:
Originally Posted by zozoo
it worked for me in sloaris , which os are you using
CentOS
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find comand directories permissions

Hi, In the code below, while the "xarsg" command does not search in "tavi_valo" subdir? IAB00201:UG02222:EXPL> ls -1|xargs -IXX find XX -name tv_va_servbonos 2>/dev/null UG02222/fuentes/TAVA/TAVA4E0000/backup/tv_va_servbonos... (2 Replies)
Discussion started by: Jose Luis
2 Replies

2. HP-UX

Script execution is very slow when trying to find all files and their owners on HP-UX box

Hi, I have a HP-UX server were I need to list all the files in the entire file system, their directory path, last modified date, owner and group. I do not need to search the file contents. I created the script given below and I am excluding directories and files of type tmp, temp and log. The... (4 Replies)
Discussion started by: Adyan Faruqi
4 Replies

3. AIX

Permissions on directories and files

Hello, I have a main directory called /test123 /test123 has lot of sub-directories and files. drwxr-x--- 21 root system 4096 Jan 25 10:20 /test123 Here, "other" does not have any access to /test123 folder. How can we provide read-only access to others on /test123... (1 Reply)
Discussion started by: aaron8667
1 Replies

4. UNIX for Dummies Questions & Answers

Awk/script to list the owners of files

I have to list the files in a directory and along with that, list the owner of each of those files. Can someone please help me with a way to get this info please? Gayathri (2 Replies)
Discussion started by: ggayathri
2 Replies

5. Shell Programming and Scripting

Script to change Permissions on files and directories

Hey, It's me again. Have a problem, that's not really a problem. I have the below script, that goes to the directory I want it to go to. lists out the directories available, lets you choose the directory you want, then it changes the permissions on said directory. using chmod -R and chown -R. ... (2 Replies)
Discussion started by: gkelly1117
2 Replies

6. Linux

Default user:group permissions while creating files and directories

Hi, I am working on setup a environment where only a specific user can upload the builds on htdocs of apache. Now i want that a specific user can copy the builds on htdocs folder. I created a group "deploy" and assign user1 and user2 to this group. On Apache side i mentioned User=deploy... (3 Replies)
Discussion started by: sunnysthakur
3 Replies

7. UNIX for Dummies Questions & Answers

how to change permissions only to files, not directories....?

Hi, I am really new to unix, any help is much appreciated. I need to change permissions of all files under several subdirectories to 700 but keep directories readable (755). Why ? Because I need a FTP user to only list his files and can't read them. But to browse to subfolder, the directories... (3 Replies)
Discussion started by: narrok
3 Replies

8. Shell Programming and Scripting

Need help in changing Permissions to 775 for files and directories

Hi All I need to create a script which would change Permissions to 775 All the Files and directories will be mentioned in the Paramter files Can anyone give a Hint how to proceed in this ?? THanks (1 Reply)
Discussion started by: ranga27
1 Replies

9. Shell Programming and Scripting

Find files based on permissions

Hi. I want to get a list of files, in a given folder, that aren't world readable (a+r). I've looked at the documentation on the FIND command, however I don't see how to list files by excluding permissions. find . -perm 644 -> would list only files that are 644 If I could use wildcards, I... (1 Reply)
Discussion started by: dmilks
1 Replies

10. UNIX for Advanced & Expert Users

How do i find files querying by permissions rights?

I'm running tikiwiki with some pretty big PHP scripts - somewhere one script has gotten uid 730 instead of 777. This invokes a PHP SAFE_MODE restriction, resulting in annoying error messages - sometimes in fatal errors. How do i perform a commandline search to find the file(s) with uid 730 i.e.... (1 Reply)
Discussion started by: anarkim
1 Replies
Login or Register to Ask a Question