# scripting problem

**URL:** <https://community.unix.com/t/scripting-problem/302759>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [January 14, 2012, 11:54am UTC](https://community.unix.com/t/scripting-problem/302759 "2012-01-14T11:54:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![esumiba](https://community.unix.com/letter_avatar/esumiba/32/5_5575768a8748004e209b776fc1b2916d.png) [@esumiba](https://community.unix.com/u/esumiba)\
**Post date:** [January 14, 2012, 11:54am UTC](https://community.unix.com/t/scripting-problem/302759/1 "2012-01-14T11:54:01Z")

</div>

HI

```nohighlight
-rw-r--r-- 1 synapse synapse 5242816 Jan 14 22:02 SMSCLOG.25
-rw-r--r-- 1 synapse synapse 1224138 Jan 14 22:14 SMSCLOG.26

```

below is the file which are generated after every 10 mins  
i am trynig do scripting in which latest generated file get cta and give ouput

I use the below code

```nohighlight
cd path; ls -lrt | tail -1 | awk '{print $9}'

```

output:

```nohighlight
SMSCLOG.26

```

now i want the code by using which i can automate the tailing of this file if

what command i can use so that latest generated file get automatically tailed ............and i can read the ou

---

<div class="post-metadata">

**Author:** ![mij](https://community.unix.com/letter_avatar/mij/32/5_5575768a8748004e209b776fc1b2916d.png) [@mij](https://community.unix.com/u/mij)\
**Post date:** [January 15, 2012, 8:01pm UTC](https://community.unix.com/t/scripting-problem/302759/2 "2012-01-15T20:01:49Z")

</div>

If you only need the filename then there is no need to use the -l flag on ls, which also saves you have to pipe to awk.

```nohighlight
tail `cd path; ls -rt | tail -1`

```

Using backticks (`) will execute the commands between them and then substitute them with their output. So in the above the name of the most recently modified file in path will be passed as the parameter to tail.
