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*

7
  • Why -f and not -e? Do we want to exclude directories, fifos etc? And you could simplify your perl to perl -lne 'print if -e' file.txt. Commented May 21, 2024 at 11:48
  • I chose -f specifically because of the question, which states "files". Couldn't get that perl construct to return any files; I assumed it was the trailing NL that stopped -f matching Commented May 21, 2024 at 12:43
  • Hmm fair. I assumed they wanted everything since that distinction (between "regular" files and weirdness) isn't very commonly known. You could well be right though. As for the NL yes, exactly, but -l turns on auto chomp. Commented May 21, 2024 at 12:51
  • Ah, thanks. I have to hold my hand up and say I'd forgotten -l completely (I don't use perl much these days). Simplifying... Commented May 21, 2024 at 13:09
  • Could be perl -lne 'print if lstat' for files of any type. -e would exclude symlinks that can't be resolved. Commented May 22, 2024 at 15:07