Home > Mobile >  Piping the output of `ls` to a second command: file or strings being passed?
Piping the output of `ls` to a second command: file or strings being passed?

Time:09-27

I'm concerned that this piped command will not do what I intended:

ls ASH* | ls -Art | tail -n 1

ls ASH* - list files with a file name starting with ASH

ls -Art | tail -n 1 - of passed files, list only the most recent one

However, in retrospect, I'm concerned that what is being piped from the first command to the second command is not actually a list of files, but rather just a list of text strings (file names), which would not make sense to the subsequent command?

CodePudding user response:

what is being piped from the first command to the second command is not actually a list of files, but rather just a list of text strings

Everything is bytes. Let's say, bytes that consist of only printable characters are usually called "text". A list of newline separated file names and a list of newline separated text strings, both are just text. It's only text everywhere.

which would not make sense to the subsequent command?

It doesn't make sense to pipe to ls, because ls doesn't read standard input. It is irrelevant of what is being piped to standard input.

does the second command understand that what is being piped to it is a list of files, from which it can access time stamps and pick out the most recent file in the list?

No.

  • Related