unix command needed

I need a one line script to find the latest log filename that starts with 'System.out' from the current folder.


I need this because I am trying run the following  command  in putty

tail -100f  <need a one line script to find the latest log filename that starts with 'System.out' from the current folder>.log


cofactorAsked:
Who is Participating?
 
TintinCommented:
No need to over complicate it.  Just do

ls -t System.out* | tail -1

0
 
MedinaExpertCommented:
tail -100f `ls -latr System.out* | cut -c 52- | tail -1`

You might have to change the 52- to adjust for you version of ls

0
 
MedinaExpertCommented:
This is actually better, sorry

tail -100f `ls -latr System.out* | tr ' ' '\n' | tail -1`
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
cofactorAuthor Commented:
what is latr ?

what is  tr ?

why new line \n you are using ?

also there is a second tail you used ...why ?

This is a complex script . Could you please explain what it is doing ?  I'm not a Unix guy. So, could you please explain in simple way.
0
 
MedinaExpertCommented:
Sure, no drama :)

tail -100f  `ls -latr System.out* | tr ' ' '\n' | tail -1`


the part between ``s is executed as a command in a command
ls -latr means Long All sorted in Time Reverse (newest listed latest)
then we change all spaces for newlines (the tr command) and only take the last line (the tail command) wich contains the last System.out* file

Hope this helps...

Cheers
0
 
MedinaExpertCommented:
true, but make it ls -t | head -1 or ls -tr | tail -1 to get the newest.
0
 
cofactorAuthor Commented:
>>>No need to over complicate it.  Just do
ls -t System.out* | tail -1

does it  show the latest ?
0
 
MedinaExpertCommented:
ls -tr System.out* | tail -1
or
ls -t System.out* | head -1

will show the newest file
0
 
cofactorAuthor Commented:
ok . I have little doubt still
>>>ls -t System.out* | head -1
Here is my understanding

ls -t  System.out*  =  list files that started with  'System.out'  sorted by last modification time.
Now, head -1  = show  first file from the beginning  of the list of files.
and "|"  is the connector  which  sends  the file list  to on which head works
0
 
ozoCommented:
that's correct
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.