[nflug] ubuntu sudo script
Mark T. Valites
mark-nflug at valites.net
Thu Jun 21 11:20:55 EDT 2007
You can also put the entire loop into a subshell that you hand off to sudo
as well:
$ sudo sh -c 'for i in `find -name *wine*`; do sudo rm -f $i; done'
Watch your shell quoting when you start doing these things.
However, for what you're doing, find has the possibility of finding files
& directories with spaces in them & handing them off to rm as separate
things to remove - ie. if 'find' finds a file named 'wine install
notes.txt', rm will try to remove three files - 'wine', 'install' &
'notes.txt' and not the file you're after.
Your best bet in this case is to use the '-exec' arg to find, which also
just happens to eliminate the original sudo loop problem:
$ sudo find -name '*wine*' -exec rm -f {} \;
-Mark
On Thu, 21 Jun 2007 joshj at linuxmail.org wrote:
> for i in `find -name *wine*`; do sudo rm -f $i; done
>
> Thus spake anthonyriga:
>
>> How do you run script commands in bash shell using sudo? I was trying
>> to delete some wine files and I get this error here is the command:
>>
>> sudo for i in `find -name *wine*`; do rm -f $i; done
>> bash: syntax error near unexpected token `do
>>
>> If I take out sudo I get permission denied. How do you
>> run scripts overiding sudo? I like the security aspect
>> of sudo but sometimes it gets to be a pain. Suggestions?
>>
>>
>>
>>
>> ____________________________________________________________________________________
>> Need Mail bonding?
>> Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
>> http://answers.yahoo.com/dir/?link=list&sid=396546091
>> _______________________________________________
>> nflug mailing list
>> nflug at nflug.org
>> http://www.nflug.org/mailman/listinfo/nflug
>>
> _______________________________________________
> nflug mailing list
> nflug at nflug.org
> http://www.nflug.org/mailman/listinfo/nflug
>
More information about the nflug
mailing list