Required help in chmod command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Required help in chmod command
# 1  
Old 10-23-2007
Required help in chmod command

I have files inside the some directories. The no. of files in each directory will vary from 1 to 500K. I need to change the permissions of all the files to 400 mode. When the files are large in numbers...the command
$chmod 400 *
fails saying "ksh: /bin/chmod: arg list too long"

so I have written a small script to do it.... like
for i in `ls`
do
chmod 400 $i
done

This script is changing the files to 400 mode, but it is taking a lot of time to complete as it has to loop through the for loop many times especially when the files are 100K or more. Is there a faster way we can do this?

Thanks for your help
-------------------------------------------
Also can anyone help me in writing a script to recursively traverse a directory and change all files to 400 and all subdirectories to 755 permissions.
# 2  
Old 10-23-2007
use find and xargs to solve this problem...

Code:
find starting-directory -type f | xargs -n 10 chmod 400

the find will print out the paths to all the files

xargs will batch these up 10 at a time (see the -n 10) and run "chmod 400 filelist" where filelist is the list of file paths.
# 3  
Old 10-23-2007
Thanks... this worked

Porter,

Thanks for your help. This worked... now it is faster.... Can we add chainging directories also to 755 in the same command or do we need to execute seperately one more command for chaging the directories. like
find <dir> -type d |xargs -n 1000 chmod 755

thanks again.

Quote:
Originally Posted by porter
use find and xargs to solve this problem...

Code:
find starting-directory -type f | xargs -n 10 chmod 400

the find will print out the paths to all the files

xargs will batch these up 10 at a time (see the -n 10) and run "chmod 400 filelist" where filelist is the list of file paths.
# 4  
Old 10-23-2007
Quote:
Originally Posted by lokachari
find <dir> -type d |xargs -n 1000 chmod 755
Absolutely!
# 5  
Old 10-24-2007
Unable to catch errors into file

I run the below command

Code:
(find <dir> -type d | xargs -n 100 chmod 755) |tee -a logfile 2>&1

But it was not able to search in one of the directories...and it printed it on screen saying
find: cannot search dir/dir1/dir2
find: cannot search dir/dir1/dir3

But this information was not captured on the logfile. How do I capture this info in the logfile as well as print it on the screen.
# 6  
Old 10-24-2007
Rather than using "tee" I tend to write all to a log file then run another session that does "tail -f logfile" if I want to watch it.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Required Command in awk command

Hi Firends, I wanted to extract the first record of the file which starst with character say "X". And I tried an awk command which works when i try to execute it individually: awk 'substr($1,1,1)=="X"' inputfile.txt But when I use the same command in my script for which I am passing the... (2 Replies)
Discussion started by: Ajay Venkatesan
2 Replies

2. Shell Programming and Scripting

How to use chmod command inside ftp block?

hi, i want to use chmod command inside ftp. so that what ever files are transfered to the local server will hav 664 permission. if i use chmod inside ftp , the file permissions gets changed in the remote server and when the file is transffered to local server using get command, it does not... (8 Replies)
Discussion started by: Little
8 Replies

3. Solaris

chmod command in SunOS

Hi Bros, I have a question want to receive your help. On SunOS server. I have 1 file in /etc. mode of file is "read only". I've used chmod 777 commmand to change mode of that file. firstly, it's ok. but about 3 mins after that. The mode of that file rollback to "read only". I don't know how.... (4 Replies)
Discussion started by: hikaru022002
4 Replies

4. Shell Programming and Scripting

One doubt regarding chmod command

which one is correct chmod 777 file.txt or chmod 777 / file.txt what is difference in these two commands? thanx in advance (2 Replies)
Discussion started by: Himanshu_soni
2 Replies

5. UNIX and Linux Applications

What is the difference between chmod in solaris and chmod in Linux?

i think it is the same in both... Iam i right? (1 Reply)
Discussion started by: sumaiya
1 Replies

6. Cybersecurity

Help Required: Command to find IP address and command executed of a user

Hi, I am trying to write a script which would figure out who has run which command and their IP. As i dont have any clue as to which commands would do this job, i request some gurus to help me on this. Thanks Vishwas (2 Replies)
Discussion started by: loggedout
2 Replies

7. Shell Programming and Scripting

Help Required regarding wc command

Hi guys, I want to find the number of records in a particular file and store that value in any other variable. I am trying this below command but it is not working and giving me an error "Uninary Operator Expected". say I have taken a variable name 'count' in which I have to store the no. of... (7 Replies)
Discussion started by: dtidke
7 Replies

8. Solaris

chmod command

Hi, I want to create one user who has right to run chmod command in solaris, Any Idea? (7 Replies)
Discussion started by: manoj.solaris
7 Replies

9. Shell Programming and Scripting

change file type to hidden using chmod command

I want to make a hidden file with chmod command. Example: I have a file name inputfile.txt -rw-r--r-- 1 xxxxxx xxxxxx 1388 Sep 12 05:41 inputfile.txt I want to hide that file using chmod command. Please tell me if it is possible or there is some other way to do this. Thanks... (2 Replies)
Discussion started by: rinku
2 Replies

10. UNIX for Dummies Questions & Answers

chmod command for recently modified files

hello! is there a way for me to use the chmod command to change permissions for several files all at once -based on the fact that these files were all most recently modified TODAY ? I can't use a wildcard on their filenames because the filenames are varied. But I was hoping I could somehow do... (2 Replies)
Discussion started by: polka_friend
2 Replies
Login or Register to Ask a Question