Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Find and change permission in linux

Posted on 2009-05-18
22
609 Views
Last Modified: 2013-12-21
Hi,

I would like to find and change the file/folder permission using the following command, but it seems to not working :

find /home/username/public_html -type d | xargs chmod -x 755
find /home/username/public_html -type f | xargs chmod -x 644
find /home/username/public_html -name *.cgi | xargs chmod -x 755
find /home/username/public_html -name *.pl | xargs chmod -x 755

Is there any wrong with the above command ?

Thank you.
0
Comment
Question by:smksa
  • 7
  • 5
  • 4
  • +3
22 Comments
 
LVL 16

Expert Comment

by:ai_ja_nai
ID: 24411447
too many parameters to chmod: get rid of that '-x'
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24411457
Hi,
don't intermix symbolic and numeric formats of chmod.
So either the '-x' (remove execute permission) or the 755 has to be left out.
wmp
 
0
 
LVL 16

Expert Comment

by:ai_ja_nai
ID: 24411469
(lol, the ol' far west quick draw challenge)
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24411495
At least I came off second-best! (OK, not very useful in some far west scenarios, I fear ...)
0
 
LVL 10

Accepted Solution

by:
lanboyo earned 200 total points
ID: 24411524
Well you are mixing chmod syntaxes. -x means remove the execute, while the numbers are explicitly setting the permissions. Should just be chmod 755 FILENAME

xargs just confuses me though.

I like to use the -exec directive in find, which would be like this. I don't know if it is supported on your system. The backslashes in front of the * and ; are to  make it shell script ready. Might not need them from the command line.

find /home/username/public_html  -name \* -type d  -exec chmod 755 {}  \;

This replaces the {} with the results of the find, and executes once for each result.

the command

find /home/username/public_html  -name \* -type d  -exec chmod 755 {} +

Does the same except that it batches the files into groups and feeds it to the command, great for when you need to delete a million files and the args list is too long for the shell.
0
 
LVL 10

Expert Comment

by:lanboyo
ID: 24411526
Third.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24411553
which one is not working?

I am not sure if chmod accepts -x option

consider putting " or ' around *.cgi  & *.pl

0
 
LVL 16

Expert Comment

by:ai_ja_nai
ID: 24411625
@omarfarid: chmod can't accept both symbolic and octal parameters at the same time

@woolmikporc: LOL
0
 
LVL 14

Assisted Solution

by:Deepak Kosaraju
Deepak Kosaraju earned 100 total points
ID: 24411699
You cannot user -x and 755 either user character type permission like a-x  (or) number code 755. Following are the only options available for chmod.
So try either of the following
find /home/username/public_html -name "*.cgi" | xargs chmod a-x
(or)
find /home/username/public_html -name "*.cgi" | xargs chmod 755

you can also try following through -exec
find /home/username/public_html -name "*.cgi"  -exec chmod 755 {} \;

find /home/username/public_html -name "*.cgi" | xargs chmod a-x
(or)
find /home/username/public_html -name "*.cgi" | xargs chmod 755
 
you can also try following through -exec
find /home/username/public_html -name "*.cgi"  -exec chmod 755 {} \;
 
 
 
OPTIONS
       Change the mode of each FILE to MODE.
 
       -c, --changes
              like verbose but report only when a change is made
 
       --no-preserve-root
              do not treat / specially (the default)
 
       --preserve-root
              fail to operate recursively on /
 
       -f, --silent, --quiet
              suppress most error messages
 
       -v, --verbose
              output a diagnostic for every file processed
 
       --reference=RFILE
              use RFILEs mode instead of MODE values
 
       -R, --recursive
              change files and directories recursively
 
       --help display this help and exit

Open in new window

0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24412212
thank you ai_ja_nai :) what I was trying to highlight to question author is that -x is not an option like -R , etc. maybe I should have used more clear statement
0
 
LVL 16

Expert Comment

by:ai_ja_nai
ID: 24412245
guh! :p
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24412285
sorry for my ignorance , but what ' guh! :p ' means?
0
 
LVL 16

Expert Comment

by:ai_ja_nai
ID: 24412308
stupified surprise due to some sort of realisation, with a tongue smile :)
0
 
LVL 2

Author Comment

by:smksa
ID: 24412717
Hi,

I have tried :

 find /home/USERNAME/public_html -name "*.cgi" | xargs chmod 755;

But the following error comeout :

chmod: missing operand after `755'
Try `chmod --help' for more information.

Hope somebody can help.

Thanks.
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 24412740
Yu'll have to escape the semicolon for -exec to work properly -
find /home/USERNAME/public_html -name "*.cgi" | xargs chmod 755 \;

0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 200 total points
ID: 24412750
... pardon, overlooked that it's 'xargs.
Try this -
find /home/USERNAME/public_html -name "*.cgi" | xargs -i{}  chmod 755 {}
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24412763
why do you need the ; ? just remove it
0
 
LVL 16

Expert Comment

by:ai_ja_nai
ID: 24412846
the error is here:

> find /home/USERNAME/public_html -name "*.cgi" | xargs chmod 755;
                                                                                                             ^

remove the ';'  , otherwise you'll terminate the command before xargs passes the argument to chmod
0
 
LVL 2

Author Comment

by:smksa
ID: 24412895
Hi,

I have removed the ";" but it make no different wit hthe error.

But the "find /home/USERNAME/public_html -name "*.cgi" | xargs -i{}  chmod 755 {}" helps .

Thanks.
0
 
LVL 16

Expert Comment

by:ai_ja_nai
ID: 24413392
I don't know what you did, but the syntax

find /my/custom/path -name "*.myextension" | xargs chmod 755

worked for me. What errors did it throw?
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24413479
you may face problem if file name contain spaces, try

find /home/username/public_html -type d | while read file
do
    chmod 755 "$file"
done
0
 
LVL 2

Author Closing Comment

by:smksa
ID: 31582567
Thanks to all
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will giveā€¦
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question