Change chmod on files in diff directories


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Change chmod on files in diff directories
# 1  
Old 01-28-2012
Change chmod on files in diff directories

I am looking for a small script to crawl through several directories and change a couple of files in each directory to read write status.

Anyone have any ideas ?
# 2  
Old 01-28-2012
Your specifications are a bit vague. Anyway,
Code:
find ./ -name "test*" -type f | xargs chmod 777

This would find all files starting with "test" in the current directory and its sub-directories and change their permissions to -rwxrwxrwx.
This User Gave Thanks to balajesuri For This Post:
# 3  
Old 01-29-2012
Thanks balajesuri.

I haven't seen xargs before. Is that a part of older UNIX languages or something from linux?

So just to elaborate a touch.

Code:
find /var/opt/mydir -name "*abc*" type -f | xargs 777

This would change the chmod on every file containing "abc" in mydir and mydir's subdirectories.

What is the alternative to xargs if xargs is not available.

Last edited by methyl; 01-29-2012 at 02:13 PM.. Reason: please user code tags
# 4  
Old 01-29-2012
Use -exec available in find

--ahamed
# 5  
Old 01-29-2012
Every character counts in Shell syntax.
Code:
balajesari's post:
find ./ -name "test*" -type f | xargs chmod 777

your post has introduced two syntax errors
find /var/opt/mydir -name "*abc*" type -f | xargs 777

The -exec version would be
find /var/opt/mydir -name "*abc*" -type f -exec chmod 777 {} \;

It's hard to think of a mainstream unix/Linux which does not have "xargs", but when posting on this forum please mention what Operating System and version you have and what Shell you prefer.

Off topic. There is never a reason to set a file's permissions to 777 . It is a security nightmare.
There is sometimes a reason to set a directory to permissions 777 , but even then 1777 is generally safer.
This User Gave Thanks to methyl For This Post:
# 6  
Old 01-29-2012
OK thanks guys. I got it to work the way I need.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to change Permissions on files and directories

Hey, It's me again. Have a problem, that's not really a problem. I have the below script, that goes to the directory I want it to go to. lists out the directories available, lets you choose the directory you want, then it changes the permissions on said directory. using chmod -R and chown -R. ... (2 Replies)
Discussion started by: gkelly1117
2 Replies

2. UNIX for Advanced & Expert Users

chmod to parent and sub directories ?

Hi folk, Could you please give me command to give the rwx permissions to the parent and its sub directories ? Is it possible to fire one command or Script for giving permission to both the parent and its sub directories. I meant to say something like in recurcive. I am using AIX 5.2 ... (2 Replies)
Discussion started by: varungupta
2 Replies

3. UNIX for Dummies Questions & Answers

chmod for files and directories

Hi, OS - Unix, linux (all unix flavors) My requirement. To check directory/file exists and then change the permission of the directories/files. Iam trying to start with directory and here is my code in the file totalchange.sh (insideragain - is a directory, test1.txt - is a file under the... (2 Replies)
Discussion started by: kenkanya
2 Replies

4. UNIX for Dummies Questions & Answers

how to change permissions only to files, not directories....?

Hi, I am really new to unix, any help is much appreciated. I need to change permissions of all files under several subdirectories to 700 but keep directories readable (755). Why ? Because I need a FTP user to only list his files and can't read them. But to browse to subfolder, the directories... (3 Replies)
Discussion started by: narrok
3 Replies

5. UNIX for Dummies Questions & Answers

Using diff on files in different directories

Hi, I want to be able to compare two different files in two different directories. I have a development server set up on one domain and a live server set up on another.....I need to be able to compare files on these two servers. Any ideas? (2 Replies)
Discussion started by: elduderino
2 Replies

6. UNIX for Dummies Questions & Answers

Batch Renaming: Change files' extensions in many sub-directories

Hi all - I'm trying to rename a large number of files all at once and need some help figuring out the command line syntax to do it. I've already done quite a bit of research with the rename and mv commands, but so far haven't found a solution that seems to work for me. So: The files exist... (10 Replies)
Discussion started by: dave920
10 Replies

7. UNIX for Advanced & Expert Users

recursive chmod that only affects directories?

The man page for chmod doesn't list a way to recursively change permissions on directories only, without affecting the files themselves. Let's say that I wanted to change the permissions on the current directory and all subdirectories. I know I can write a bash script that would do this using... (1 Reply)
Discussion started by: retrovertigo
1 Replies

8. UNIX for Advanced & Expert Users

change permission chmod

Hi, when I launch my perl script, I write on the shell: perl x.pl How I can can change the permission to write only: x to launch the program? (2 Replies)
Discussion started by: Minguccio75
2 Replies

9. Shell Programming and Scripting

Change permission for directories and files

Is there a way to change subdirectories permission plus the files in the subdirectories in a directory i specified without using the find command? (1 Reply)
Discussion started by: mingfei2006
1 Replies

10. Shell Programming and Scripting

diff 2 files; output diff's to 3rd file

Hello, I want to compare two files. All records in file 2 that are not in file 1 should be output to file 3. For example: file 1 123 1234 123456 file 2 123 2345 23456 file 3 should have 2345 23456 I have looked at diff, bdiff, cmp, comm, diff3 without any luck! (2 Replies)
Discussion started by: blt123
2 Replies
Login or Register to Ask a Question