Copy last n-lines from one file to another

50,996

Since jasonwryan hasn't turned their comment into an answer, I'll put this here just to close the question. If you prefer one of the answers from Wildcard's link instead, we can close this Q as a duplicate.

for dest in file1 file2 file.3rd
do
  tail -n 5 /path/to/source/file >> "$dest"
done

...where 5 is the number of lines to grab. I put a loop around it just to demonstrate one way to do it -- you could put a glob there instead (/home/userx*/.bashrc for example).

Share:
50,996

Related videos on Youtube

f1rstsurf
Author by

f1rstsurf

Quite frankly, even if the choice of C were to do nothing but keep the C++ programmers out, that in itself would be a huge reason to use C. In other words: the choice of C is the only sane choice. I know Miles Bader jokingly said "to piss you off", but it's actually true. I've come to the conclusion that any programmer that would prefer the project to be in C++ over C is likely a programmer that I really would prefer to piss off, so that he doesn't come and screw up any project I'm involved with. The only way to do good, efficient, and system-level and portable C++ ends up to limit yourself to all the things that are basically available in C. And limiting your project to C means that people don't screw that up, and also means that you get a lot of programmers that do actually understand low-level issues and don't screw things up with any idiotic "object model" crap. So I'm sorry, but for something like git, where efficiency was a primary objective, the "advantages" of C++ is just a huge mistake. The fact that we also piss off people who cannot see that is just a big additional advantage. -- Linus Torvalds

Updated on September 18, 2022

Comments

  • f1rstsurf
    f1rstsurf almost 2 years

    In the context of adding the same lines at end of the .bashrc or .vimrc files of several user accounts on the same machine, what would be an easy way to copy the last n-lines from one shell script to another?