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*

6
  • This requires that the filenames do not contain whitespace characters such as space or newline. It also requires GNU find. Commented Jul 18, 2018 at 12:07
  • of course. I wrote it this way for simplicity. You can easily fix it by using zero delimiter. option -0 for xargs and print0 for find. Commented Jul 18, 2018 at 12:09
  • 1
    Good people never use whitespace in filenames anyway... :-D Commented Jul 18, 2018 at 12:09
  • I don't think I mentioned anything about the character set used for the filenames in the question, apart from them ending with .txt. So there can be no assumptions made. Good people write code to support any valid Unix filename. Using -print0 and -0 with find and xargs will help partway through the pipeline (if you have tools that support these options), but you'll have the same issue when you get to ls and head later, especially if the filenames contain newlines. Commented Jul 18, 2018 at 12:16
  • no insult was intended. I hoped you are here to learn, and simple is better than complex if you want to learn. Extended solution included for you. Commented Jul 18, 2018 at 12:28