Solved

unix command needed

Posted on 2010-08-25
10
261 Views
Last Modified: 2013-12-06
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


0
Comment
Question by:cofactor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 1

Expert Comment

by:MedinaExpert
ID: 33528316
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
 
LVL 1

Expert Comment

by:MedinaExpert
ID: 33528334
This is actually better, sorry

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

Author Comment

by:cofactor
ID: 33528392
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:MedinaExpert
ID: 33528543
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
 
LVL 48

Accepted Solution

by:
Tintin earned 50 total points
ID: 33528745
No need to over complicate it.  Just do

ls -t System.out* | tail -1

0
 
LVL 1

Expert Comment

by:MedinaExpert
ID: 33528762
true, but make it ls -t | head -1 or ls -tr | tail -1 to get the newest.
0
 

Author Comment

by:cofactor
ID: 33529085
>>>No need to over complicate it.  Just do
ls -t System.out* | tail -1

does it  show the latest ?
0
 
LVL 1

Assisted Solution

by:MedinaExpert
MedinaExpert earned 50 total points
ID: 33529093
ls -tr System.out* | tail -1
or
ls -t System.out* | head -1

will show the newest file
0
 

Author Comment

by:cofactor
ID: 33529443
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
 
LVL 84

Expert Comment

by:ozo
ID: 33529548
that's correct
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
unix in java example 9 88
Replace Ubuntu Desktop with Ubuntu Server 7 144
ifconfig related commands 6 18
Permit ONLY SFTP service on AIX 7.2 system 4 25
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question