LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Bulk Permission (https://www.linuxquestions.org/questions/linux-newbie-8/bulk-permission-66905/)

linuxfond 06-20-2003 03:03 PM

Bulk Permission
 
I incidentally changed permissions on all folders in home directory to 644. This has lead to severla problems.

How can I change it back to 755 without having to click every and each folder and click permissions back to 755 using the mouse?

Is it possible to change permissions to 644 or 755 depending on the file type from a shell using just one or two commands?

Thanks in advance for your advise,
Lu

MasterC 06-20-2003 03:17 PM

How to change every file/directory:
chmod -R 755 /path/to/home/directory

Change based on filetype, that's probably going to require a bit (see that as A LOT) more work. However, look into possibly man file and then man chmod.

Good Luck

Cool

cuckoopint 06-20-2003 10:37 PM

What exactly do you mean by 'file type'? As in a specific extension, or binary, etc?

linuxfond 06-21-2003 07:12 AM

Thanks, guys, for your tips. I will try to chmod as you wrote. By file types I mean folders (which I want to be chmoded to 755), html files or office files chmoded to 644, and shell scripts chmoded to 751 or something, so that it is executable.
Of course, there are many folders in my home folder, and each folder within the home folder contain other folders. These folders contain different files, such as html's, swx's, png's, sh etc, shell scripts without file name extensions.... You see the problem? If I do each file by hand it will take me days, and in any way I will overlook something.
For example, at this moment I can't run tar because there are wrong permissions. So the backup script (which run tar command) aborts with errors.
Lu

cuckoopint 06-21-2003 10:06 AM

Well, let's see.

For folders, you could try something as simple as:

Code:

for i in `find ~/ -type d`
do
  chmod 755 $i
done

Which could of course be written in one line:

for i in `find ~/ -type d`; do chmod 755 $i; done

The same idea goes for everything else - to find some kind of patterns. I'm assuming all the html files end in an extension.

How about the scripts? Maybe they all have a particular line of text, such as "#!/bin/sh"?

Maybe a way to check if you didn't miss a file is to find all files with the permission 644 and then removing the files you want to have that permission.

cuckoopint 06-21-2003 10:08 AM

btw, you said you messed up your home dir. Why is tar in your home dir?

nchauhan 06-21-2003 10:35 AM

Hey guys, can I ask similar question in this thread?

1. It might sound naive but how do I change the ownership of the directory? By mistake on my system /home/user1 has ownership of "root" but I want to make it "user1".

2. Why user1 is not able to create a directory in his/her home directory on my system? i.e. if user1 tries to create a directory "xyz" in /home/user1 then it gives an error saying "permission denied".

Thank you all.

cuckoopint 06-21-2003 11:03 AM

nchauhan, I'm not a mod, but you shouldn't hijack ppl's threads.

1. man chown
chown user:group /path/to/dir #see the manpage for more info

2. check permissions/ownership of directory. The user does not have rights to create files, if one cannot write to the directory.

nchauhan 06-21-2003 11:13 AM

Sorry i did not intend to do that.

Thank you for help, though.

linuxfond 06-21-2003 12:19 PM

All right. Tar is of course not in my home dir, but tar doesn't like to backup directories which do not have read and execute permissions, and it doesn't backup files which have no read permissions. You see the problem? shell script files start with #!/bin/bash
Well, just a moment, I will try your scripts (they are sh scripts, right?)

linuxfond 06-21-2003 12:25 PM

[QUOTE]Originally posted by cuckoopint
[B]
Code:

for i in `find ~/ -type d`
do
  chmod 755 $i
done

Hm..., it doesn't run. If I try to run it as non-root it aborts: Permission denied or failed to get attributes, or No such file or directory; if I run it as root it aborts telling:
bash: /root/: is a directory

linuxfond 06-21-2003 12:35 PM

[QUOTE]Originally posted by MasterC
How to change every file/directory:
chmod -R 755 /path/to/home/directory


Good. This indeed seem to have changed all the files to 755. That permits me at least to run daily backups of the daily work.

I will study further on how to change permissions on the files inside the folders depending on whether it is pl, shtml, or scripts.
Certainly I don't need to give global exec permissions on the scripts

Thanks :)

cuckoopint 06-21-2003 06:38 PM

Quote:

Hm..., it doesn't run.
I don't know why. Worked for me.
instead of a script, try it from command line:

Code:

cd ~
mkdir temp; cd temp
touch file1; touch file2
mkdir ~/temp/new
#^testing purposes
cd ~/temp
chmod -R 777 .
for i in `find ~/ -type d`; do chmod 755 $i; done
ls -l


linuxfond 06-22-2003 03:43 AM

Thanks for your help. Basically, the problem of schedulled backups is solved by chmoding everything to 755.

I chmoded scripts residing in my home dir in a similar way to rwx-r-r.

I don't see how could I possibly chmod contents of other folders to rw-r-r leaving the folders rwx-rx-rx.

Any other tip?

cuckoopint 06-22-2003 11:44 AM

Quote:

I don't see how could I possibly chmod contents of other folders to rw-r-r leaving the folders rwx-rx-rx.
I'm not sure if this is what you mean:

[code]
for i in `find -type d /path/to/dir`; do chmod 733 $i; done
for i in `find -not -type d /path/to/dir`; do chmod 644 $i; done
[/code}

?


All times are GMT -5. The time now is 02:55 AM.