Brainlocked over recursive script.
Hi all! This is almost embarasing.. I am trying to recursively chmod a series of files. I tried doing ls -R * | while read f do if [ -f $f ]; then chmod 644 $f fi done Unfortunately the filenames contain spaces... And thus i get all kinds of errors from the chmod stage 2004 So Called Chaos -bash: [: too many arguments And the stupid part is i cant for my life understand how to get the script to enclose the $f with " " (Or get it to understand the complete filename.) I guess i could (somehow) convert all spaces in both folder and file name to underscores, but i dont know how to do that either... As you probably understood, my scripting knowledge is close to NIL... Any pointer or hints thankfully received... -- /Rikard ----------------------------------------------------------------------------- email : rikard.j@rikjoh.com web : http://www.rikjoh.com mob: : +46 (0)763 19 76 25 ------------------------ Public PGP fingerprint ---------------------------- < 15 28 DF 78 67 98 B2 16 1F D3 FD C5 59 D4 B6 78 46 1C EE 56 >
Per Jessen wrote:
Rikard Johnels wrote:
This is almost embarasing.. I am trying to recursively chmod a series of files.
chmod -R ?
/Per Jessen, Zürich
Is a better option find <dir> -type f -exec chmod 644 {} \; Replace <dir> with the required path or use . for the currect dir. chmod 644 on a directory means you wont be able to cd into it. Steve
On Saturday 27 May 2006 13:06, Stephen Allewell wrote:
Per Jessen wrote:
Rikard Johnels wrote:
This is almost embarasing.. I am trying to recursively chmod a series of files.
chmod -R ?
/Per Jessen, Zürich
Is a better option
find <dir> -type f -exec chmod 644 {} \;
Replace <dir> with the required path or use . for the currect dir.
chmod 644 on a directory means you wont be able to cd into it.
Steve
-- Check the headers for your unsubscription address For additional commands send e-mail to suse-linux-e-help@suse.com Also check the archives at http://lists.suse.com Please read the FAQs: suse-linux-e-faq@suse.com
That seems so have done the trick :) Thanks! Again thinking of taking a programming course... Question is what script language to get into... Perl, bash..? -- /Rikard ----------------------------------------------------------------------------- email : rikard.j@rikjoh.com web : http://www.rikjoh.com mob: : +46 (0)763 19 76 25 ------------------------ Public PGP fingerprint ---------------------------- < 15 28 DF 78 67 98 B2 16 1F D3 FD C5 59 D4 B6 78 46 1C EE 56 >
On Saturday 27 May 2006 12:09, Rikard Johnels wrote:
ls -R * | while read f do if [ -f $f ]; then chmod 644 $f fi done
Unfortunately the filenames contain spaces... And thus i get all kinds of errors from the chmod stage
2004 So Called Chaos -bash: [: too many arguments
And the stupid part is i cant for my life understand how to get the script to enclose the $f with " "
I did not test it, but I would code it as this: ls -R * | while read f; do if [ -f "$f" ]; then chmod 644 "$f" fi done Cheers, Leen
On Monday 29 May 2006 14:56, Leendert Meyer wrote:
ls -R * | while read f; do if [ -f "$f" ]; then chmod 644 "$f" fi done
No, it's fundamentally broken. ls doesn't print the full path, so the only result from the above (except for the files in the top level directory) is a lot of "No such file or directory" errors. Per's "find" works
On Monday 29 May 2006 14:59, Anders Johansson wrote:
On Monday 29 May 2006 14:56, Leendert Meyer wrote:
ls -R * | while read f; do if [ -f "$f" ]; then chmod 644 "$f" fi done
No, it's fundamentally broken.
Not if it is used in a directory without any subdirectories. ;P But yes, I missed that one. ;)
ls doesn't print the full path, so the only result from the above (except for the files in the top level directory) is a lot of "No such file or directory" errors. Per's "find" works
I would use that too. Cheers, Leen
participants (5)
-
Anders Johansson
-
Leendert Meyer
-
Per Jessen
-
Rikard Johnels
-
Stephen Allewell