LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 10-04-2004, 10:15 AM   #1
0.o
Member
 
Registered: May 2004
Location: Raleigh, NC
Distribution: Debian, Solaris, HP-UX, AIX
Posts: 208

Rep: Reputation: 35
Permission Automation


Okay, I am trying to write a script to help with changing permissions. What I would like it to do is look at a directory and all sub directories and change the permissions on files with a given extension. For instance if there have been 30 .doc files sent to the server all being in different directories I would like to be able to change their permissions in one fatal swoop.

Thanks.
 
Old 10-04-2004, 12:47 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397Reputation: 2397
One way of doing this is to use find:

$ find . -type f -name "*doc" -exec chmod 644 {} \;

Don't know if find is familiar to you, so here's a little breakdown of the command:

The . (dot) tells find were to start looking. A . (dot) starts looking from the dir you execute the command from. /home/user (a 'hard' path) is also legal.

-type f tells find to look for files and not directories, which would be -type d.
-name "*doc" here the name, or part of it can be given. This one looks for files that end with doc.

-exec chmod 644 {} \; find enables you to execute other unix command from within its structure. chmod 644 is excuted on every file found.

Please be carefull if you are not experienced with the -exec <command> {} \; structure.
One 'trick' to test if all is well: -exec echo "<command>" {} \;
Instead of executing the command it will be echoed.

For details: man find and google.

Hoipe this helps.
 
Old 10-04-2004, 01:07 PM   #3
0.o
Member
 
Registered: May 2004
Location: Raleigh, NC
Distribution: Debian, Solaris, HP-UX, AIX
Posts: 208

Original Poster
Rep: Reputation: 35
Yes, that does help. Thank you!

If anyone else has some input on other ways to go about doing this I would appreciate it also. You can never have too many ways to go about doing things.

Last edited by 0.o; 10-04-2004 at 01:08 PM.
 
Old 10-04-2004, 01:32 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
Druuna's method is the by far most efficient and
effective ... :)


You could write a complicated script to
ls -R through the directories, parse the directory
structure out, grep for doc and ... nuh, stuff that ... :}



Cheers,
Tink
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
automation bong.mau Programming 2 09-06-2005 03:26 PM
Office Automation pudhiyavan Linux - Software 0 01-07-2005 01:24 AM
OpenOffice automation with C++ Paulo Ges Linux - Software 2 10-22-2004 08:55 AM
Mouse automation? Viper168 Linux - Software 6 11-11-2003 09:19 AM
ftp automation Mad_C Linux - General 12 09-15-2003 08:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 11:37 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