Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to delete all the files that do not start with __. This

ls | grep -v "__" | xargs -0 rm

Yields : File name too long. Any help?


ls | grep -v "__" | awk '{print("rm \42"$0"\42")}' | /bin/bash

solves the problem, but I'd like to know why the first is not correct. Thanks

share|improve this question
up vote 3 down vote accepted

Take out the -0 argument and it will fix this problem. the -0 arg to xargs says that the items in the input list are null terminated. You aren't doing that, you are passing lines terminated by an \n character.

share|improve this answer

Your Answer


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.