Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Automatically changing the permissions of only certain files in subdirectories

Posted on 2004-03-28
6
Medium Priority
?
269 Views
Last Modified: 2010-04-20
Hello.

I need to change the permission of all files with the following extentions inside of a certain directory to 777:
.dat
.bak
.lock

There are over 200 files in 15 sub-directories.

I have ssh access. How can I change the permissions of all the files in all the subdirectories at once? Thanks!
0
Comment
Question by:perldog
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10698288
Use the find command:

find /path/to/parent -name "*.dat" -print | xargs chmod 777
find /path/to/parent -name "*.bak" -print | xargs chmod 777
find /path/to/parent -name "*.lock" -print | xargs chmod 777
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 920 total points
ID: 10698292
You can also combine the three extensions into one command:
find /path/to/parent -name "*.dat" -print , -name "*.bak" -print , -name "*.lock" -print | xargs chmod 777

0
 
LVL 9

Assisted Solution

by:tkalchev
tkalchev earned 80 total points
ID: 10704517
Or try this one (it is almost equivalent ) :

find /path/to/parent -name "*.dat" -exec chmod 777 {} \; , -name "*.bak" -exec chmod 777 {} \; , -name "*.lock" -exec chmod 777 {} \;
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10705071
tkalchev,
your solution will be slower: You are forking the chmod command for every single file. The xargs mechanism collects a number of file names and then forks one chmod command for a number of files.
0
 
LVL 9

Expert Comment

by:tkalchev
ID: 10705157
True, but no chance for "argument list too long" error :)
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10705211
... and for 200 files it does not make a big difference :-)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Fine Tune your automatic Updates for Ubuntu / Debian
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question