The differences between "cat filename" and "cat < filename"

:roll_eyes: Hi. I’ve wondered what the differences of “cat filename” and “cat < filename” are?
can anyone explain for me ?
And What is the purpose of using redirection?
Thanks so much. :yum:

In this case it’s a very subtle difference, but a difference nonetheless.

cat filename.txt <-- in this case, the program cat opens the file

cat < filename.txt <-- in this case, the shell (i.e. the command line program) opens the file, and passes it to cat as an input.

If you’re interested, there’s more on it here:

In terms of its purpose, it depends on what you’re trying to achieve. In many cases, it simply allows you to redirect the flow of data from one source to another, in a simple, single command. For example, you could write ls > file_list.txt to write the contents of a directory straigt into a text file.


Thanks so much.I got it

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.