1827870 Members
1132 Online
109969 Solutions
New Discussion

Re: about linux commands

 
sbtsantosh
New Member

about linux commands

How to print the last but one file in a directory?
4 REPLIES 4
Ivan Krastev
Honored Contributor

Re: about linux commands

Use:

ls | tail -1

regards,
ivan
James R. Ferguson
Acclaimed Contributor

Re: about linux commands

Hi:

If you mean how do you print only the last file in a directory, then:

# ls -l /path | grep "^-" | tail -1

...which limits everything to regular files in '/path' and returns only the last one.

Regards!

...JRF...
Steven E. Protter
Exalted Contributor

Re: about linux commands

Shalom,

Works well in Unix too. Or the Linux forums.

http://forums12.itrc.hp.com/service/forums/familyhome.do?familyId=118

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Dennis Handly
Acclaimed Contributor

Re: about linux commands

>How to print the last but one file in a directory?

I assume that you don't want "last file", otherwise you would have said so, and want file N-1:
ls | tail -2 | head -1

(This prints any type of "file".)