- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to change the file & directory permission?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2006 07:21 AM
10-09-2006 07:21 AM
In one directory, There are so many sub directories & files.
and under sub-directories, there are also so many sub-directories,
At present, all files & subdirectories mode is 777.
i want to change it 755 for sub-ditectories & 644 for files.
how can i do it because there are so many files & sub directories and i can not change it one by one.
Please suggest.
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2006 07:26 AM
10-09-2006 07:26 AM
Solutionfind /parent/dir -type d -exec chmod 755 {} \;
find /parent/dir -type f -exec chmod 644 {} \;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2006 07:26 AM
10-09-2006 07:26 AM
Re: How to change the file & directory permission?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2006 07:31 AM
10-09-2006 07:31 AM
Re: How to change the file & directory permission?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2006 07:31 AM
10-09-2006 07:31 AM
Re: How to change the file & directory permission?
If you want to recursively change the permissions and/or ownership of all files and directories beneath a directory, simply do:
# chmod -R 644 /pathname
...and/or:
# chown -R root:sys /pathname
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2006 07:37 AM
10-09-2006 07:37 AM
Re: How to change the file & directory permission?
Yes, I should read better. Jonathan is correct --- you need to handle directories and files separately. *However* it is much more efficient to do:
# find /path -xdev -type f | xargs chmod 644
# find /path -xdev -type d | xargs chmod 755
Note htat the '-xdev' option prevents 'find' from traversing mountpoints.
The use of 'xargs' instead of '-exec' means that 'xargs' wil bundle many arguments into one execution at a time (automatically!). Instead of creating a separate process for every file or directory 'find' finds, you will create substantially fewer, thereby *greatly* speeding up your execution time. Your users will thank you!
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2006 07:39 AM
10-09-2006 07:39 AM
Re: How to change the file & directory permission?
I think Jonathan & lvan are right,
james: I dont want recursive change.
I want to change it 755 for sub-ditectories & 644 for files.
under sub directories, Again there are also so many sub-directories & files.
Should i go with these commadns?
#find /parent/dir -type d -exec chmod 755 {} \;
#find /parent/dir -type f -exec chmod 644 {} \;
what is in last column ( is it \-slash and ;- semi colon)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2006 07:40 AM
10-09-2006 07:40 AM
Re: How to change the file & directory permission?
Praveen,
If you want to be sure, run the following commands:
/usr/bin/find
/usr/bin/find
This will create two files: one that lists all of the world writable directories, and one that lists all of the world writable files.
You can then review the contents for accuracy, and then add the following line to start of each line in the file
chmod o-w
Make the above script executable and run it to flip the world writable flag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2006 07:59 AM
10-09-2006 07:59 AM
Re: How to change the file & directory permission?
Please understand that 'find' is *recursive*. That is, unless you skip an entity below the starting directory, 'find' will descend every sub-directory in the tree that you specify for it.
My second post, simply pointed out that you could handle directories and files independently, *and* that less resources would be used if you used a piped 'xargs' rather than an '-exec' with 'find'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2006 08:19 AM
10-09-2006 08:19 AM
Re: How to change the file & directory permission?
James' commands will work more efficiently than the ones I posted -- especially if there is a very large number (thousands) of directories and files being changed. The -xdev flag will keep find from traversing different filesystems, so keep that in mind if you have filesystems mounted underneath the directory you are wanting to do this for.
As an aside, the characters at the end are indeed a backslash \ and a semi-colon ;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2006 09:42 AM
10-09-2006 09:42 AM
Re: How to change the file & directory permission?
# find . -type f -exec chmod 644 {} \; -o -type d -exec chmod 755 {} \;
however for performance it is better to pipe the output to xargs as the man page for find(1) says...excerpt below.
Change permissions on all regular files in a directory subtree to mode 444, and permissions on all directories to 555:
find pathname -type f -print | xargs chmod 444
find pathname -type d -print | xargs chmod 555
Note that output from find was piped to xargs(1) instead of using
the -exec primary. This is because when a large number of files
or directories is to be processed by a single command, the -exec
primary spawns a separate process for each file or directory,
whereas xargs collects file names or directory names into
multiple arguments to a single chmod command, resulting in fewer
processes and greater system efficiency. The + delimiter for the
-exec primary can be used to achieve the same efficiency.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2006 12:00 PM
10-09-2006 12:00 PM
Re: How to change the file & directory permission?
chmod -R is one of the three MOST DANGEROUS commands in UNIX. This is because everyone forgets that specific permissions are required for both functional as well as secure operations. chmod -R changes everything and you can read here in the forums several stories of how one command destroyed the entire computer operation. Never use chmod -R unless there is no other way (and there is always another way).
The 3 most dangerous (root) commands (in order of popularity for catatrophes):
1. rm -rf
2. chmod -R
3. dd
Bill Hassell, sysadmin