Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-30-2007, 11:18 AM
|
#1
|
LQ Newbie
Registered: Oct 2007
Posts: 1
Rep:
|
Recursively chmod directories
...how do I?
I have a dir structure with .html, .php etc.
I can use:
chmod -R 644 *.html
chmod -R 755 *.php
ok, but can't find a way to change all dirs to e.g. 755
tried getting a list of dirs and pipe to chmod:
sudo ls -R | grep :$ | sed s/:// | chmod 755
(am running ubuntu)
just comes back chmod: missing operand after `755'
yours frustratedly
Simon.
|
|
|
10-30-2007, 11:36 AM
|
#2
|
LQ Newbie
Registered: Sep 2004
Distribution: Fedora 7
Posts: 15
Rep:
|
chmod
you can just cd to the directory you want to change it's permissions and type:
chmod -R 755 ./
|
|
|
10-30-2007, 11:49 AM
|
#3
|
LQ Guru
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509
|
Piping a list of directories, that literally are strings separated by newlines, does not tell to chmod what to do. You can use xargs to build and execute commands from the standard input, as in
Code:
sudo ls -R | grep :$ | sed s/:// | xargs chmod 755
A better way to do can be
Code:
sudo find ./test_dir -type d -exec chmod 755 {} \;
this looks for directories under test_dir and execute the specified command on every item found. See man xargs and man find for details.
|
|
|
10-30-2007, 11:51 AM
|
#4
|
LQ Veteran
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809
|
You have directory names with extensions like .html?? seems unusual, but I'm not sure how it is relevant.
chmod -R will change everything (directories and files)--I think you are saying you want to change directories only.
I would suggest a loop starting with:
for f in `ls -R` do
...
...
done
what this does is make a list of values in the variable "f", you can then test each one using--eg--the "file" command. If the test shows it is a directory, then:
chmod 755 $f
Note: In your other code, you were grepping using ":$" I assume you meant this to mean ":" at the end of the line. Trouble is, the ":" is not part of the actual directory name---I suspect it is just the character that your terminal uses to designate a directory.
|
|
1 members found this post helpful.
|
10-30-2007, 12:23 PM
|
#5
|
Member
Registered: Oct 2006
Location: The Ether
Distribution: Ubuntu 16.04.7 LTS, Kali, MX Linux with i3WM
Posts: 299
Rep:
|
Code:
for i in
`ls -al | grep '^d' | awk ' NR > 2 ' | awk '{print $9}'` ;
do chmod 7XX $i ;
done
There must be a way of combining the two awk commands ?
i.e print only the 9th field of all but the first 2 lines ?
It would make the above script look a bit shorter.
Last edited by uncle-c; 10-30-2007 at 12:29 PM.
|
|
|
10-30-2007, 12:28 PM
|
#6
|
Senior Member
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530
Rep:
|
I've always done it in two steps. The -print0 argument to find and the -0 argument to xargs mean that the list of files is de-limited with the NULL character - this can save you problems if there are file names with spaces in:
Code:
find /path/to/files -type d -print0 |xargs -0 chmod 755
find /path/to/files -type f -print0 |xargs -0 chmod 644
|
|
|
10-31-2007, 01:01 PM
|
#7
|
Member
Registered: Dec 2005
Distribution: RedHat, Ubuntu
Posts: 101
Rep:
|
IGNORE ME: someone else posted this higher up...
why not just
Code:
find . -type d -exec chmod 0755 {} \;
pitfall: besure to back-escape that semicolon to protect it from your shell. The semi needs to go as an arg to find, not a command sep eaten by your shell 
Last edited by cconstantine; 10-31-2007 at 01:02 PM.
|
|
|
All times are GMT -5. The time now is 08:37 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|