17
tail */filename

works, but

tail -1 */filename

doesn't. Why is this? And is there a 1 liner to perform this task without loops?

head -1 */filename

works for some strange reason.

mrkent
  • 333
  • 2
  • 4
  • 13
  • Thanks, that works, but can you explain why it does that? – mrkent Apr 27 '12 at 16:01
  • Also, what's the best way to tail and list them in natural numeric order, like the way ls -v does. I think just using tail */filename, directories 1, 10, 11, 12, etc would be listed together, while I want 1, 2, 3, 4, ... to be listed together. Thanks. – mrkent Apr 27 '12 at 16:08
  • `head` and `tail` are just designed differently; `tail` requires `-n`, `head` uses `-n` for any number `n`. You should post your other request as a separate question, to make it easier for others to find in the future. – chepner Apr 27 '12 at 16:33
  • It is difficult to offer solutions when the problem statement is simply, "it doesn't work". Please [edit] your question to give a more complete description of what you expected to happen and how that differs from the actual results. See [ask] for hints on what makes a good explanation. – Toby Speight Apr 27 '17 at 15:36

2 Answers2

32

While head works with -1 on multiple files, tail does not. But it works with the -n argument instead:

tail -n 1 */filename
Casper
  • 33,403
  • 4
  • 84
  • 79
7

If you are still looking for answer please try below one :

Go to the directory in which file are available and execute below command

ls -1|while read file; do tail -1 $file; done
Fabich
  • 2,768
  • 3
  • 30
  • 44