Solved

unix command needed

Posted on 2010-08-25
10
255 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
10 Comments
 
LVL 1

Expert Comment

by:MedinaExpert
Comment Utility
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
Comment Utility
This is actually better, sorry

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

Author Comment

by:cofactor
Comment Utility
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
 
LVL 1

Expert Comment

by:MedinaExpert
Comment Utility
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
Comment Utility
No need to over complicate it.  Just do

ls -t System.out* | tail -1

0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 1

Expert Comment

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

Author Comment

by:cofactor
Comment Utility
>>>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
Comment Utility
ls -tr System.out* | tail -1
or
ls -t System.out* | head -1

will show the newest file
0
 

Author Comment

by:cofactor
Comment Utility
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
Comment Utility
that's correct
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

After running Ubuntu some time, you will be asked to download updates for fixing bugs and security updates. All the packages you download replace the previous ones, except for the kernel, also called "linux-image". This is due to the fact that w…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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 navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now