Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I try to delete all symbolic links pointing to Python3.2 with

sudo ls -l . | grep '../Library/Frameworks/Python.framework/Versions/3.2' | awk '{print $9}' | xargs rm

This just gives

rm: 2to3: Permission denied
rm: 2to3-3.2: Permission denied
rm: idle3: Permission denied
rm: idle3.2: Permission denied
rm: pydoc3: Permission denied
rm: pydoc3.2: Permission denied
rm: python3: Permission denied
rm: python3-32: Permission denied
rm: python3-config: Permission denied
rm: python3.2: Permission denied
rm: python3.2-32: Permission denied
rm: python3.2-config: Permission denied
rm: python3.2m: Permission denied
rm: python3.2m-config: Permission denied
rm: pythonw3: Permission denied
rm: pythonw3-32: Permission denied
rm: pythonw3.2: Permission denied
rm: pythonw3.2-32: Permission denied

What gives?

Ps. there are similar threads, but there the answer/solution is that the asker did not use sudo.

share|improve this question
    
Actually you also do not use sudo (at least not in the sense you think :)). Try your line with ... xargs sudo rm –  qbi Nov 1 '12 at 16:35
    
@qbi Ah, I think I even understand why. Thanks. Post it as an answer and I will accept it. Might be more newbs wondering about the same thing. –  The Unfun Cat Nov 1 '12 at 16:37
add comment

1 Answer

up vote 0 down vote accepted

Actually you also do not use sudo (at least not in the sense you think): only the ls command is run under sudo, then the output of sudo ls -l . goes through the pipe. Try your line with:

\ls -l . | grep '../Library/Frameworks/Python.framework/Versions/3.2' | awk '{print $9}' | sudo xargs rm

(\ls nullifies any alias that you may have for ls, which may cause the output format to change.)

share|improve this answer
1  
Note that ls mangles some special characters and xargs expects input quoted in a peculiar way, so this command only works if the file names involved do not contain any special characters. Also, it doesn't work with user names containing spaces, which is possible on OSX IIRC. –  Gilles Nov 1 '12 at 17:41
1  
It's better not to parse ls: Greg's wiki. –  Francesco Turco Nov 2 '12 at 13:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.