Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Security
User Name
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.


  Search this Thread
Old 01-05-2005, 11:49 AM   #1
Registered: Jul 2003
Location: USA
Distribution: Slack 12.2 and Ubuntu 9.04
Posts: 61

Rep: Reputation: 15
set file permissions for 100 directories & its files

I have a directory called /Data
It has many directories; probably 100. Inside those dir I have executable files - They shouldn't be executable.
For example lets just say /Data has 2 directories calles /folder1 and /folder2

I would like to be at /Data and issue one command to give the
subsequent directories rwxr xr x and its
subsequent files rw r r

Can this be done or do I have to go to each of the 100 directories and
chmod -x * ??
Old 01-05-2005, 12:02 PM   #2
Registered: Oct 2004
Location: Brooklyn
Distribution: Slackware 14.1, 14.2; Debian Jessie; Debian Stretch
Posts: 314

Rep: Reputation: 38
I have always found its easier dealing with numbers when modifying permissions. Read is 4, write 2, and execute 1. This means the rx is 5 and rw is 6. With that in mind, it would issue a chmod -R 644 * That would (recursively) from the attach point change permissions to rw,r,r.
Old 01-05-2005, 12:18 PM   #3
Registered: Jul 2003
Location: USA
Distribution: Slack 12.2 and Ubuntu 9.04
Posts: 61

Original Poster
Rep: Reputation: 15
I've tried that already. It doesnt work becasue:

it takes away the x permission on all the directories, making it impossible for other users to read the file.
drw-r--r-- 2 Smith users 3208 Mar 13 2004 temp/
-rw-r--r-- 1 Smith users 153454 Aug 5 2002 sample

I need other users to be able to look into the directory and read the files.
Old 01-05-2005, 06:31 PM   #4
Registered: Dec 2003
Location: Vienna | Austria
Distribution: Gentoo
Posts: 52

Rep: Reputation: 15
I have asked myself this question - but I still have not found a solution.
you are able to list the files and (sub)directories in a directory.
ls -d
ls --directory
you should
list directory entries instead of contents
(from ls --help).
I think this means that you can see all (sub)directories in the choosen directory. Further I think if you can find this out, it's simple to write a short script doing what you want.
The problem is: ls -d shows me only the directory itself with one dot. nothing more.
Old 01-06-2005, 04:11 AM   #5
Registered: Dec 2002
Location: California
Distribution: Slackware & LFS
Posts: 799

Rep: Reputation: 33
1) cd /Data

2) chmod -R 755 *

3) find ./ -type f | xargs chmod 644

Step 2 is just to be sure your directories are correct.

Step 3 will find any 'regular' files (see 'man find' for other types), and then make them non-executable.

--- Cerbere

Last edited by Cerbere; 01-06-2005 at 04:12 AM.
Old 01-06-2005, 08:56 AM   #6
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679Reputation: 679
Another way of doing it is using the -exec option of the find command.

1) cd /Data
2) find ./ -type d -exec chmod 755 {} \;
3) find ./ -type f -exec chmod 644 {} \;

If only a handful of files and directories need changing, you can add the -perm test to return files with execute permissions for Groups and Others.


If this directory is truly a data directory, and its own partition, consider also using the -noexec option when mounting. You the owner won't be able to execute files from there either, but this is added insurance.

Last edited by jschiwal; 01-06-2005 at 09:11 AM.
Old 01-06-2005, 11:23 AM   #7
Registered: Jul 2003
Location: USA
Distribution: Slack 12.2 and Ubuntu 9.04
Posts: 61

Original Poster
Rep: Reputation: 15
thanks for your replies.


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
file permissions not being remembered for SAMBA printer files/directories Avatar Linux - General 0 08-30-2005 02:44 PM
change file permissions recursivly without changing permission of directories eNTi Linux - Software 8 10-15-2004 04:37 PM
permissions for group files/directories transferred from Netware mweil Linux - Newbie 1 07-01-2004 11:36 PM
file permissions windows directories lfent Linux - General 5 02-17-2004 05:43 PM
How do I change permissions of files/directories? Okashira Linux - Newbie 5 01-12-2004 06:11 PM > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 10:44 AM.

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