LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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


Reply
  Search this Thread
Old 03-27-2013, 01:26 PM   #1
jay.singh
LQ Newbie
 
Registered: Mar 2013
Posts: 3

Rep: Reputation: Disabled
Smile changing directory permissions .


m new to linux . and was practicing on my system . ok so i wish to change the permissions of all the directories inside /etc directory to 777 ,just with 2-3 lines of commands , how should i proceed ?
 
Old 03-27-2013, 01:32 PM   #2
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Before I answer your question, you really shouldn't chmod your whole /etc tree, due to security reasons. That being said though, you can use chmod for this simple task, as such:
Code:
chmod -R 777 /etc
The -R flag means to use chmod recursively, which is what you would want to do to change permissions for all files and subdirectories within /etc. Hope this helps!

Cheers,

Josh
 
1 members found this post helpful.
Old 03-27-2013, 01:37 PM   #3
jay.singh
LQ Newbie
 
Registered: Mar 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
well thanx fr reply ,but what if i want to change permission of subdirectories only , not the files in /etc . AS there are numerous subdirectories in /etc , so thats obvious 'm not going to change permission one by one . need some alternate way out !

Last edited by jay.singh; 03-27-2013 at 01:47 PM.
 
Old 03-27-2013, 01:47 PM   #4
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Use the following then:
Code:
find /etc/ -mindepth 1 -type d
This will find all directories, with a minimum of one directory deep, in /etc for you. Now from here, you can use either the -exec argument with the find command, or you can pipe that to xargs, as such:
Code:
find /etc/ -mindepth 1 -type d | xargs chmod 777  # this is the xargs example

find /etc/ -maxdepth 1 -type d -exec chmod 777 {} \;  # this is using only the find command without piping to xargs, using -exec
Hope this helps!

Josh

Edit - You can also read up the man pages for the find and xargs commands for more information. Type "man find", etc.

Last edited by corp769; 03-27-2013 at 02:10 PM.
 
2 members found this post helpful.
Old 03-27-2013, 02:01 PM   #5
jay.singh
LQ Newbie
 
Registered: Mar 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
thank you !
 
Old 03-27-2013, 02:03 PM   #6
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Anytime! Do you have any more questions? If not, can you please mark your thread as solved located at the top of this page? Thanks!
 
Old 03-27-2013, 02:07 PM   #7
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,396

Rep: Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017
Quote:
Originally Posted by corp769 View Post
Code:
find /etc/ -maxdepth 1 -type d -exec chmod -R 777 {} \;  # this is using only the find command without piping to xargs, using -exec
Probably just a typo, but that should be:
Code:
find /etc/ -maxdepth 1 -type d -exec chmod 777 {} \;
To prevent chmod from recursively modifying the permissions of the files in those subdirectories.
 
Old 03-27-2013, 02:10 PM   #8
corp769
LQ Guru
 
Registered: Apr 2005
Posts: 5,817

Rep: Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002Reputation: 1002
Ahh, that was. Thanks for that, my fingers tend to type more than what I really think.
 
Old 03-27-2013, 10:17 PM   #9
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,019

Rep: Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455Reputation: 2455
however chmodding /etc to 777
might cause your system to never boot again

security programs like SELinux check things like folder permissions and if not correct
it will not boot
it should be 755 and 644
 
Old 03-28-2013, 03:30 AM   #10
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 521

Rep: Reputation: 141Reputation: 141
when i switched from Windows to CentOS, i copied tons of files from ntfs usb drive to ext4 home folder. In CentOS default user's permission for directory is 775 and 664 for files.

So,
Code:
# find -type d -iname "*" -exec chmod -R 0775 {} \;
# find -type f -iname "*" -exec chmod -R 0664 {} \;
# find -iname "*" -exec chown -R user:user {} \;
also, if you are interested in mass file renaming, check http://www.linuxquestions.org/questi...ng-4175453776/

Last edited by mddnix; 03-28-2013 at 03:33 AM.
 
Old 03-28-2013, 09:46 AM   #11
suicidaleggroll
LQ Guru
 
Registered: Nov 2010
Location: Colorado
Distribution: OpenSUSE, CentOS
Posts: 5,396

Rep: Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017Reputation: 2017
Quote:
Originally Posted by mddesai View Post
when i switched from Windows to CentOS, i copied tons of files from ntfs usb drive to ext4 home folder. In CentOS default user's permission for directory is 775 and 664 for files.

So,
Code:
# find -type d -iname "*" -exec chmod -R 0775 {} \;
# find -type f -iname "*" -exec chmod -R 0664 {} \;
# find -iname "*" -exec chown -R user:user {} \;
also, if you are interested in mass file renaming, check http://www.linuxquestions.org/questi...ng-4175453776/
Couple of things

1) What is the point of -iname "*"? Why bother including it since it's not filtering anything?
2) You're already finding all directories, so the -R flag in the first chmod is redundant and very inefficient since it's going to be chmodding ALL files in ALL directories multiple times
3) The -R in the second chmod is doing nothing since you're only matching files
4) The -R in the chown is redundant and very inefficient since you're already running the command on all files and directories

Last edited by suicidaleggroll; 03-28-2013 at 09:48 AM.
 
1 members found this post helpful.
Old 03-28-2013, 09:59 AM   #12
mddnix
Member
 
Registered: Mar 2013
Distribution: Redhat, Ubuntu
Posts: 521

Rep: Reputation: 141Reputation: 141
Quote:
Originally Posted by suicidaleggroll View Post
Couple of things

1) What is the point of -iname "*"? Why bother including it since it's not filtering anything?
2) You're already finding all directories, so the -R flag in the first chmod is redundant and very inefficient since it's going to be chmodding ALL files in ALL directories multiple times
3) The -R in the second chmod is doing nothing since you're only matching files
4) The -R in the chown is redundant and very inefficient since you're already running the command on all files and directories
hmmm. never thought about that. thanks.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing directory and file permissions annec0010 Linux - Newbie 3 04-18-2012 02:16 PM
Permissions denied - changing directory rust8y Solaris / OpenSolaris 1 08-08-2006 07:22 PM
Changing Directory Permissions trevor4706 Fedora 2 06-13-2006 06:37 PM
Directory permissions changing back? elderain Linux - Newbie 0 03-08-2004 06:02 PM
Changing directory permissions Bagsy Linux - Newbie 1 07-08-2003 05:50 AM


All times are GMT -5. The time now is 11:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration