Shell Script problem
Hi,
I'm wondering if anyone can help me make a script that searches through a specific folder (in this case /tmp ) for files with a given permissions (755) and then delete all the other files with different permissions? The correct permission should be, as mentioned 755, and those are the files that should be kept (not deleted). All other files in this folder with different permissions should be deleted. Thanks! :) |
Quote:
Since this seems VERY much like a homework question, your teacher can also help you, as well as the man pages on the find and ls commands. |
I'm sorry, I didn't intended for you to make it for me, but help me along the way. Preferable with guidelines so that I can learn from it. I might be stupid, but I've been reading a lot about it, but it's so new for me that I sometimes feels like a huge question mark while reading it. A simple explanation of why this is wrong would've been greatly appreciated, and hopefully with a nudge towards what could be different.
Okay, so what I've written is this: Code:
#!/bin/bash When I run the bash script, I just use the filename ( ./snd ) command for it, if that matters. |
What you have looks like you have taken some syntax elements from the find command and tried to use them in isolation... which obviously does not work.
Try playing around with find: Code:
find /tmp/ -type f ! -perm 755 EDIT: Oops. You already did that part. So you are almost there. Look at man find to see how the -exec flag works. |
Quote:
|
Don't use the test '[]' brackets for commands. Just use 'if' and the command.
Besides the '-delete' you could also pipe to xargs. Code:
if find ./tmp -type f ! -perm 755 |
Thanks for the replies!
So it seemed to work perfectly when I removed the brackets, thanks a lot for that heads-up metaschima! Also tried with the xargs command, but somehow it overlooked the "rules" and just deleted all the files in the folder... So I went back to test with the -delete function (now that the brackets was removed), and it worked flawlessly. So thanks a lot for the help, everyone. |
All times are GMT -5. The time now is 03:19 AM. |