Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • Parsing the output of ls is not a good idea. It'll mostly work here, but a wildcard-based solution will completely work, so why settle for second-best? Commented Apr 23, 2012 at 23:16
  • "ls -1" give you only the file names if that's what you mean. Commented Apr 24, 2012 at 16:46
  • In most cases, yes. In general, no. Try (in bash/ksh/zsh) touch junk precious $'junk\nprecious'; ls -1 | grep junk | xargs -l rm. You didn't really care about that precious file, did you? Not to mention that restriction to at most 1000 files, or the fact that you find 03.jpg when you're looking for 3.jpg. I retract my comment for second-best, this is really broken, and it's incomplete to boot. Commented Apr 24, 2012 at 17:26