I want to get the last 10 lines of multiple files. I know they all end with "-access_log". So I tried:
tail -10 *-access_log
But this gives me an error, where as:
tail -10 file-*
Gives me the output I'd expect. I would think this probably has more to do with BASH then tail. However commands like:
cat *-access_log
Work fine.
Any suggestions?
I believe you would want:
As to why:
I don't think it has anything to do with globbing:
I think it just so happens that your glob expands to one file. It probably has something to do with some archaic options parsing that I am too lazy to try to read, but if you really want to know go look in
tail.c
in the coreutils source and dissect the following function:While a bit old, the question is still relevant. I met a similar problem
that gave me the error
however, tailing only one file, like
works fine. Looking at the source tail.c shows that tail starts by parsing obsolete options, then parse the rest (i.e. options not processed yet), regular options. However,
parse_obsolete_option()
expects an "obsolete" usage, with only one file as argument.So when providing more files, the function returns immediately, and let the regular parser to choke on
-2
(expecting-n 2
).In conclusion, it is better to always use the
-n
regular form, knowing that the "obsolete" code only accepts one file.Actually this behavior of GNU tail(-COUNT only accepts one file) is documented. https://www.gnu.org/software/coreutils/manual/html_node/tail-invocation.html
It could also be found in coreutils info page installed.
Note that on the contrary, "head -COUNT" supports multiple files.