Skip to main content
gaaah. nap time would be nice...
Source Link
geekosaur
  • 32.9k
  • 5
  • 84
  • 59

You need to use xargs to turn standard input into arguments for rm.

$ ls | grep '^Dar' | xargs rm 

(Beware of special characters in filenames; with GNU grep, you might prefer

$ ls | grep -Z '^Dar' | xargs -0 rm 

)

Also, if you're using bash, you can make it handle that kind of pattern directly, although itwhile the shell doesn't supportuse regexps as such, that's a simple pattern:

$ shopt -s extglob; rm !(Dar*) 

(meanwhile, I think I need more sleep.)

You need to use xargs to turn standard input into arguments for rm.

$ ls | grep '^Dar' | xargs rm 

(Beware of special characters in filenames; with GNU grep, you might prefer

$ ls | grep -Z '^Dar' | xargs -0 rm 

Also, if you're using bash, you can make it handle that kind of pattern directly, although it doesn't support regexps as such:

$ shopt -s extglob; rm !(Dar*) 

)

You need to use xargs to turn standard input into arguments for rm.

$ ls | grep '^Dar' | xargs rm 

(Beware of special characters in filenames; with GNU grep, you might prefer

$ ls | grep -Z '^Dar' | xargs -0 rm 

)

Also, while the shell doesn't use regexps, that's a simple pattern:

$ rm Dar* 

(meanwhile, I think I need more sleep.)

Source Link
geekosaur
  • 32.9k
  • 5
  • 84
  • 59

You need to use xargs to turn standard input into arguments for rm.

$ ls | grep '^Dar' | xargs rm 

(Beware of special characters in filenames; with GNU grep, you might prefer

$ ls | grep -Z '^Dar' | xargs -0 rm 

Also, if you're using bash, you can make it handle that kind of pattern directly, although it doesn't support regexps as such:

$ shopt -s extglob; rm !(Dar*) 

)