using ls -ltr : display only last four file names

Hi ,

Server details �

Machine hardware: sun4u
OS version: 5.9
Processor type: sparc
Hardware: SUNW,Sun-Fire-880

When I put ls �ltr command I get �

/users/testuser> ls -ltr
-rw-rw-r--   1 testuser  dba           76 Jan 13  2009 ftp.scr
-rwxr-xr-x   1 testuser  dba         1436 Jan 13  2009 menudb_qa
-rw-rw-r--   1 testuser  dba           16 Jan 26  2009 test.dat20090126
-rw-rw-r--   1 testuser  dba          112 Mar 10  2009 exp_vaucc2.log
drwxrwxr-x   3 testuser  dba         1024 Mar 24  2009 data
drwxrwxr-x   2 testuser  dba           80 Aug 18  2009 tmp_dblogs
-rw-rw-r--   1 testuser  dba          189 Sep  9 05:21 test.txt
-rw-rw-r--   1 testuser  dba          149 Sep  9 05:22 t.txt
-rw-rw-r--   1 testuser  dba           77 Dec 31 07:46 afiedt.buf
 
 

But want the command to display only last 4 file names �

Expected result �

/users/testuser> 
drwxrwxr-x   2 testuser  dba           80 Aug 18  2009 tmp_dblogs
-rw-rw-r--   1 testuser  dba          189 Sep  9 05:21 test.txt
-rw-rw-r--   1 testuser  dba          149 Sep  9 05:22 t.txt
-rw-rw-r--   1 testuser  dba           77 Dec 31 07:46 afiedt.buf
 

Plz help.

You could combine tail with the command i.e

ls -ltr |tail -4

Thank you!!

ls -lrt | tac | head -4 | tac

How about this?

ls -lrt | sed '6,$!d'

hi thillai_selvan your answer is not working for me.

ls -lrt | sed '6,$!d'

if the number of line is more than 100. how you get the last 4 lines.

thanks for your feedbacks. According to the user input I have wrote the above command.

If you want to satisfy for all the cases you just use the following command

ls -lrt | sed -e :a -e '$q;N;5,$D;ba'