Confusion about tail usage
Nils Kassube
kassube at gmx.net
Mon Feb 18 15:49:54 UTC 2008
stan wrote:
> I am trying to write a quick shell script to delete all but the newest
> 3 files in a directory. Getting a list sorted by time, I use ls -t. I
> figured I could use tail to print all the lines in it's input file,
> skipping the first 3 lines. I expected tail -n +3 would do this. But it
> does not.
>
> What am I doing wrong?
From <http://www.gnu.org/software/coreutils/manual/coreutils.html>:
| If any option-argument is a number n starting with a ‘+’, tail begins
| printing with the nth item from the start of each file, instead of from
| the end.
So if you use "ls -t|tail -n +4" it will begin with the 4th filename, i.e.
skip the first 3 ones.
Nils
More information about the ubuntu-users
mailing list