LinuxQuestions.org
Help answer threads with 0 replies.
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 06-20-2003, 04:03 PM   #1
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Rep: Reputation: 30
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
 
Old 06-20-2003, 04:17 PM   #2
MasterC
LQ Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 68
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
 
Old 06-20-2003, 11:37 PM   #3
cuckoopint
Member
 
Registered: Feb 2003
Distribution: Debian
Posts: 797

Rep: Reputation: 30
What exactly do you mean by 'file type'? As in a specific extension, or binary, etc?
 
Old 06-21-2003, 08:12 AM   #4
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Original Poster
Rep: Reputation: 30
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
 
Old 06-21-2003, 11:06 AM   #5
cuckoopint
Member
 
Registered: Feb 2003
Distribution: Debian
Posts: 797

Rep: Reputation: 30
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.
 
Old 06-21-2003, 11:08 AM   #6
cuckoopint
Member
 
Registered: Feb 2003
Distribution: Debian
Posts: 797

Rep: Reputation: 30
btw, you said you messed up your home dir. Why is tar in your home dir?
 
Old 06-21-2003, 11:35 AM   #7
nchauhan
Member
 
Registered: Jun 2003
Location: TX, USA
Distribution: Red Hat 9.0
Posts: 43

Rep: Reputation: 15
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.
 
Old 06-21-2003, 12:03 PM   #8
cuckoopint
Member
 
Registered: Feb 2003
Distribution: Debian
Posts: 797

Rep: Reputation: 30
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.
 
Old 06-21-2003, 12:13 PM   #9
nchauhan
Member
 
Registered: Jun 2003
Location: TX, USA
Distribution: Red Hat 9.0
Posts: 43

Rep: Reputation: 15
Sorry i did not intend to do that.

Thank you for help, though.
 
Old 06-21-2003, 01:19 PM   #10
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Original Poster
Rep: Reputation: 30
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?)
 
Old 06-21-2003, 01:25 PM   #11
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Original Poster
Rep: Reputation: 30
[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

Last edited by linuxfond; 06-21-2003 at 01:30 PM.
 
Old 06-21-2003, 01:35 PM   #12
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Original Poster
Rep: Reputation: 30
[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

Last edited by linuxfond; 06-21-2003 at 01:39 PM.
 
Old 06-21-2003, 07:38 PM   #13
cuckoopint
Member
 
Registered: Feb 2003
Distribution: Debian
Posts: 797

Rep: Reputation: 30
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
 
Old 06-22-2003, 04:43 AM   #14
linuxfond
Member
 
Registered: Jan 2003
Location: Belgium
Distribution: Mandrake 9.2
Posts: 475

Original Poster
Rep: Reputation: 30
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?
 
Old 06-22-2003, 12:44 PM   #15
cuckoopint
Member
 
Registered: Feb 2003
Distribution: Debian
Posts: 797

Rep: Reputation: 30
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}

?
 
  


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
Bulk Image Maniulation doctorwebbox Linux - Software 1 10-20-2004 04:58 AM
Fetchmail & Yahoo! Bulk. dredgemortle Linux - Software 0 07-21-2004 12:57 AM
Bulk File Renaming nevereverend Linux - Newbie 11 07-03-2004 06:28 PM
bulk mail lynger Linux - Software 2 05-21-2004 01:14 AM
Bulk Mailer jgaraas Linux - Software 4 05-29-2003 11:43 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:47 PM.

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