[opensuse] Script problem
Hello all! I am (unsuccessfully) trying to arrange the usermod and permissions on some 5.000 folders and 20.000 files. (My music collection) I cant for my life compose a script that: a. Will set all directories to chmod 755 b, will set all regular files to perm 644 i tried a fairly simple script: #!/bin/sh ls -R * | while read f do echo $f if [ -f $f ]; then chmod 644 $f fi done the layout of the files is something like the following: /1_sort/Bon Jovi/Crossroads (Best of 84-94) Crossroad (best of 84-94) - 01 - Livin' On A Prayer.mp3 Crossroad (best of 84-94) - 02 - Keep The Faith.mp3 Crossroad (best of 84-94) - 03 - Someday I'll Be Saturday Night.mp3 Crossroad (best of 84-94) - 04 - Always.mp3 Crossroad (best of 84-94) - 05 - Wanted Dead Or Alive.mp3 Crossroad (best of 84-94) - 06 - Lay Your Hands On Me.mp3 Crossroad (best of 84-94) - 07 - You Give Love A Bad Name.mp3 Crossroad (best of 84-94) - 08 - Bed Of Roses.mp3 Crossroad (best of 84-94) - 09 - Blaze Of Glory.mp3 Crossroad (best of 84-94) - 10 - In These Arms.mp3 Crossroad (best of 84-94) - 11 - Bad Medicine.mp3 Crossroad (best of 84-94) - 12 - I'll Be There For You.mp3 Crossroad (best of 84-94) - 13 - In & Out Of Love.mp3 Crossroad (best of 84-94) - 14 - Runaway.mp3 Crossroad (best of 84-94) - 15 - Never Say Goodbye.mp3 But running the script yields: chmod: cannot access `$f': No such file or directory 1_Sort_me/Bon Jovi/Crossroads (Best of 84-94): -bash: [: too many arguments Crossroad (best of 84-94) - 01 - Livin' On A Prayer.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 02 - Keep The Faith.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 03 - Someday I'll Be Saturday Night.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 04 - Always.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 05 - Wanted Dead Or Alive.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 06 - Lay Your Hands On Me.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 07 - You Give Love A Bad Name.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 08 - Bed Of Roses.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 09 - Blaze Of Glory.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 10 - In These Arms.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 11 - Bad Medicine.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 12 - I'll Be There For You.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 13 - In & Out Of Love.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 14 - Runaway.mp3 -bash: [: too many arguments Crossroad (best of 84-94) - 15 - Never Say Goodbye.mp3 -bash: [: too many arguments Can anyone tell me what i do wrong, and how to write it properly?
On Sun, 15 Jun 2008 05:45:58 Rikard Johnels wrote:
Hello all!
I am (unsuccessfully) trying to arrange the usermod and permissions on some 5.000 folders and 20.000 files. (My music collection) I cant for my life compose a script that: a. Will set all directories to chmod 755 b, will set all regular files to perm 644
i tried a fairly simple script:
#!/bin/sh ls -R * | while read f do echo $f if [ -f $f ]; then chmod 644 $f fi done
the layout of the files is something like the following:
/1_sort/Bon Jovi/Crossroads (Best of 84-94)
Crossroad (best of 84-94) - 01 - Livin' On A Prayer.mp3 Crossroad (best of 84-94) - 02 - Keep The Faith.mp3 [...] Can anyone tell me what i do wrong, and how to write it properly?
Rikard, Your problem is most likely the spaces in the filenames; bash interprets each filename as a list of arguments rather than a file. You should be able to do it on the command line like this: To change all the subdirectories of the current working directory: find -type d -print0 | xargs -0 chmod 0755 This will find all directories under the current directory and set their perms to 0755. Similarly with the files: find -type f -print0 | xargs -0 chmod 0644. There was a whole thread on using xargs for this purpose a couple of months ago. See the man pages for xargs and find for more explanations. Hope this helps. -- =================================================== Rodney Baker VK5ZTV rodney.baker@iinet.net.au =================================================== George Orwell 1984. Northwestern 0. -- Chicago Reader 10/15/82
On Saturday 14 June 2008 23:12:05 Rodney Baker wrote:
On Sun, 15 Jun 2008 05:45:58 Rikard Johnels wrote:
Hello all!
I am (unsuccessfully) trying to arrange the usermod and permissions on some 5.000 folders and 20.000 files. (My music collection) I cant for my life compose a script that: a. Will set all directories to chmod 755 b, will set all regular files to perm 644
To change all the subdirectories of the current working directory:
find -type d -print0 | xargs -0 chmod 0755
This will find all directories under the current directory and set their perms to 0755.
Similarly with the files: find -type f -print0 | xargs -0 chmod 0644.
I think the following commands will do: find . -type f -exec chmod 644 \{\} \; find . -type d -exec chmod 755 \{\} \; No need to use xargs. Also note the use of "." to indicate the current directory, which the previous poster forgot. -- Erwin Lam (erwinlam@dds.nl) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (4)
-
Erwin Lam
-
Jim Cunning
-
Rikard Johnels
-
Rodney Baker