Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Find and change permission in linux

Posted on 2009-05-18
22
Medium Priority
?
631 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 800 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 400 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 800 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

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

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…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

564 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