Solved

Find and change permission in linux

Posted on 2009-05-18
22
610 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
[X]
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
  • 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Google Dork query 7 70
Replacing multiple embedded commas in a CSV file with sed 10 28
Merging two files with Perl 5 33
Why is my $_POST not going to results page 10 42
Utilizing an array to gracefully append to a list of EmailAddresses
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

730 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