Use stdout as argument of next command

Posted on 2008-01-25
Medium Priority
Last Modified: 2010-04-21
I want to tail -f a log file. The application dynamicall names its log files using the date, so each time the app is run the log file looks something like "myapp-2008-01-18-18-29-17-686.log". There are many log files, but I know I just want to tail the last one. I have taken this approach to discover which is the latest:

$ ls -trC1 myapp*.log | tail -1

That displays to stdout the file I am interested in. I cannot figure out if it is possible to somehow pipe that or redirect it somehow as the ARGUMENT of another tail -f command. This does NOT work because the last tail command is just tailing stdin:

$ ls -trC1 myapp*.log | tail -1 | tail -f

Any ideas? I'm open to other suggestions, but I'd like to keep it simple and do it in one line instead of a script...
Question by:Earthworm
LVL 46

Accepted Solution

Kent Olsen earned 500 total points
ID: 20745776
Hi Earthworm,

Piece of cake.  :)

tail -f ` ls -trC1 myapp*.log | tail -`

Good Luck,
LVL 48

Expert Comment

ID: 20745864
Or a shorter version

tail -f `ls -t mpapp*.log | head -1`

Author Closing Comment

ID: 31425098
Thanks, I knew it would be easy!

Featured Post

A proven path to a career in data science

At Springboard, we know how to get you a job in data science. With Springboard’s Data Science Career Track, you’ll master data science  with a curriculum built by industry experts. You’ll work on real projects, and get 1-on-1 mentorship from a data scientist.

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.

Join & Write a Comment

It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses

587 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