Home » Infrastructure » Unix » Command to get first line
Command to get first line [message #214957] Thu, 18 January 2007 14:09 Go to next message
mchittib
Messages: 87
Registered: September 2005
Member
Hi there,

I am using ksh. If I have a command ls -t , how can i display only the first filename of the list.

Your help is appreciated.

Thanks,
mchittib.

Re: Command to get first line [message #214960 is a reply to message #214957] Thu, 18 January 2007 14:35 Go to previous messageGo to next message
mchittib
Messages: 87
Registered: September 2005
Member
got it.

ls -t | head -1


Thanks.
Re: Command to get first line [message #215298 is a reply to message #214960] Sat, 20 January 2007 13:13 Go to previous messageGo to next message
tarundua
Messages: 1080
Registered: June 2005
Location: India
Senior Member

or

ls -rt|tail -1

Wink
Re: Command to get first line [message #215311 is a reply to message #215298] Sat, 20 January 2007 19:48 Go to previous messageGo to next message
rleishman
Messages: 3728
Registered: October 2005
Location: Melbourne, Australia
Senior Member
or..

ls -t | awk 'NR==1'

c'mon people, how many can we get. I still want to see solutions for sed, perl, and - if its possible - find
Re: Command to get first line [message #215314 is a reply to message #215311] Sun, 21 January 2007 00:14 Go to previous messageGo to next message
ebrian
Messages: 2794
Registered: April 2006
Senior Member
I'll fulfill the sed version:

ls -t | sed -n '1p'
Re: Command to get first line [message #215400 is a reply to message #214957] Mon, 22 January 2007 02:30 Go to previous message
tahpush
Messages: 961
Registered: August 2006
Location: Stockholm/Sweden
Senior Member

One of the many "find"

find . -ls|tail -1
Previous Topic: Configuration for sending mails.
Next Topic: Oracle/SunOS query
Goto Forum:
  


Current Time: Mon Nov 25 02:28:57 CST 2024