ksh; Change file permissions, update file, change permissions back?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ksh; Change file permissions, update file, change permissions back?
# 1  
Old 09-29-2011
ksh; Change file permissions, update file, change permissions back?

Hi, I am creating a ksh script to search for a string of text inside files within a directory tree. Some of these file are going to be read/execute only. I know to use chmod to change the permissions of the file, but I want to preserve the original permissions after writing to the file. How can I do this as I may have hundreds of files that are not writable but need the update?

I'll be using this find command to search the files:
Code:
find . -type f -name "*" -exec grep -ls ABC {} \;

Then I'll be using sed or perl to change "ABC" to "XYZ" for example.

Some of the files will be writable and some won't. Thanks for any assistance you can give.

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.


# 2  
Old 09-29-2011
Only for not owner's writable files.

Before
Code:
chmod u+w file

After
Code:
chmod u-w file

# 3  
Old 09-30-2011
Thanks but like I said I have mix of files that are writable and some that are not. For the ones that are currently writable I don't want to remove the write bit.
How can I update a many files of mixed permissions and preserve the original permissions after the update? Thanks!
# 4  
Old 09-30-2011
index all files permissions in a file , then change permission and modify the files as you wish, then use the indexed file to change permissions back.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Sftp change file permissions

Hi All, Apologies if this question has been asked before. I havent been able to resolve an issue and would like some help. I am getting files pushed to me via sftp. The files once pushed to my server in folder ABC have -rw------- but I need these files to have the following -rw-rw---- to be... (1 Reply)
Discussion started by: israr75
1 Replies

2. Windows & DOS: Issues & Discussions

script to change widows update permissions

I want to allow windows update when ordinary users are logged on, I'm pretty sure that adjusting the permissions registry entry HEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/WindowsUpdate to allow acces to all domins users does the trick. I already have a logon.bat that runs at... (0 Replies)
Discussion started by: barrydocks
0 Replies

3. UNIX for Dummies Questions & Answers

I am not able change the file permissions

while trying to view the access permissions to file by "ls -lrt" command it is opening some files int the dir after that segmentation fault ie core is generarting the dir.will anybody please what is the problem. (1 Reply)
Discussion started by: rajkumar_g
1 Replies

4. Shell Programming and Scripting

How can we change the permissions of a file in a directory

Hi All, I am trying to wite a Shell script which changes the permission of the files in a folder but stuck at a particular point,please help. The scenario is as follwoing: I am having a list of 10 files and a folder which has 100 files. I need to copare the list and the folder ,for... (4 Replies)
Discussion started by: Sriram.Vedula53
4 Replies

5. UNIX for Advanced & Expert Users

script to recursively change permissions on file and dirs differently?

Hi there, I need to change all files/dirs 1. all files with 744 2. all dirs with 755 is there a script for that ? thanks, thegunman (13 Replies)
Discussion started by: TheGunMan
13 Replies

6. UNIX for Dummies Questions & Answers

unzip and change file permissions

Hi, Is there any way to unzip a zip file and change file permissions to 777 while extracting the files. Does the file permissions on the zip file has to do anything with it(like zip read permissions only result in read uncompressed files etc.,)? Thanks, jp (2 Replies)
Discussion started by: jpk
2 Replies

7. Shell Programming and Scripting

We need to change the file permissions and ownerships?

I am running a linux centos server; our php script generates plenty of files in a directory, anything up to 1000 (though too often more).The files in these directories have permissions and ownerships which i need to change. I have used shell comment for changing the file permission which is... (1 Reply)
Discussion started by: nilson
1 Replies

8. UNIX for Advanced & Expert Users

How to change the permissions of ksh?

Suppose, I want to execute unix commands. For that I have to go to ksh, but if I don't have execute permission to ksh itself then is there any way to change the permission of ksh? chmod command does not work for this because, I don't have permission to ksh itself... :) Let me know, if you have... (3 Replies)
Discussion started by: ponnuvel
3 Replies

9. Solaris

File Permissions change date

Hi, I was wondering if there is any way to find out when the file/directory's permissions were changed. Typically, when using 'chmod' to change a file/directory's permissions, the modification date does not change. Any help would be greatly appreciated. Thanks. (4 Replies)
Discussion started by: kpatel
4 Replies

10. Shell Programming and Scripting

checking file's permissions and change them

Hi all, I am very new to UNIX and Shell scripting, I need to run a script to check for file's and directoires permissions and change the permissions if necessary. I appreciate your help.. Thanks (7 Replies)
Discussion started by: K-ONE
7 Replies
Login or Register to Ask a Question