Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 10-15-2009, 09:01 PM   #1
Registered: Sep 2009
Posts: 36

Rep: Reputation: 16
Get the absolute path of the latest file modified on a directory

Hi, as per the thread's title, I'm trying to get the absolute path of the file. Using ls and tail, I could the file I need but it won't show the absolute path. So I'm trying to do it using find, but not having success on it. Here's some snippets:

[oracle@mortonlx methodr]$ ls -ltr /home/oracle/admin/MORTOND/udump/
total 120
-rw-r----- 1 oracle oinstall   619 Oct 13 11:20 mortond_ora_12756.trc
-rw-r----- 1 oracle oinstall   935 Oct 13 11:21 mortond_ora_12811.trc
-rw-r----- 1 oracle oinstall   619 Oct 13 11:21 mortond_ora_12813.trc
-rw-r----- 1 oracle oinstall  2686 Oct 13 11:21 mortond_ora_12838.trc
-rw-r----- 1 oracle oinstall   840 Oct 13 11:22 mortond_ora_12862.trc
-rw-r----- 1 oracle oinstall  1619 Oct 13 11:22 mortond_ora_12867.trc
-rw-r----- 1 oracle oinstall   757 Oct 13 11:22 mortond_ora_12873.trc
-rw-r----- 1 oracle oinstall  1164 Oct 13 11:22 mortond_ora_12878.trc
-rw-r----- 1 oracle oinstall   805 Oct 13 11:23 mortond_ora_12879.trc
-rw-r----- 1 oracle oinstall   676 Oct 13 11:23 mortond_ora_12907.trc
-rw-r----- 1 oracle oinstall   619 Oct 13 11:23 mortond_ora_12882.trc
-rw-r----- 1 oracle oinstall   805 Oct 13 11:23 mortond_ora_12938.trc
-rw-r----- 1 oracle oinstall   619 Oct 13 11:23 mortond_ora_12946.trc
-rw-r----- 1 oracle oinstall   676 Oct 13 11:23 mortond_ora_12973.trc
-rw-r----- 1 oracle oinstall  1165 Oct 13 13:30 mortond_ora_18472.trc
-rw-r----- 1 oracle oinstall   619 Oct 13 13:35 mortond_ora_20080.trc
-rw-r----- 1 oracle oinstall   676 Oct 13 13:35 mortond_ora_20107.trc
-rw-r----- 1 oracle oinstall  1951 Oct 13 13:35 mortond_ora_20112.trc
-rw-r----- 1 oracle oinstall   645 Oct 13 13:54 mortond_ora_3852.trc
-rw-r----- 1 oracle oinstall   669 Oct 13 13:54 mortond_ora_3881.trc
-rw-r----- 1 oracle oinstall  1886 Oct 13 13:54 mortond_ora_3883.trc
-rw-r----- 1 oracle oinstall   617 Oct 15 13:45 mortond_ora_7555.trc
-rw-r----- 1 oracle oinstall   674 Oct 15 13:45 mortond_ora_7582.trc
-rw-r----- 1 oracle oinstall  1952 Oct 15 13:45 mortond_ora_7583.trc
-rw-r----- 1 oracle oinstall  2754 Oct 15 14:02 mortond_ora_7790.trc
-rw-r----- 1 oracle oinstall 19737 Oct 15 19:35 mortond_ora_12047.trc

[oracle@mortonlx methodr]$ find /home/oracle/admin/MORTOND/udump/ -type f -mmin 40 -print
[oracle@mortonlx methodr]$ 

Expected output:
Thank you very much!!
Old 10-15-2009, 09:55 PM   #2
Senior Member
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 115Reputation: 115
I guess I am confused. You already have the absolute path of the directory. Why don't you just append the file that you find with ls to that?

Your find command is only going to return a file that was changed 40 minutes ago. Not one that was changed 41 minutes ago or one that was changed 39 minutes ago.
Old 10-15-2009, 10:05 PM   #3
Registered: Sep 2009
Posts: 36

Original Poster
Rep: Reputation: 16
Yeah, more like this, if this is the proper way:

[oracle@mortonlx methodr]$ echo "/home/oracle/admin/MORTOND/udump/"$(ls -tr /home/oracle/admin/MORTOND/udump/ | tail -1)
[oracle@mortonlx methodr]$
I just thought on the command

[oracle@mortonlx methodr]$ ls -tr /home/oracle/admin/MORTOND/udump/ | tail -1
[oracle@mortonlx methodr]$
that there would be something like a:

[oracle@mortonlx methodr]$ reversebasename $(ls -tr /home/oracle/admin/MORTOND/udump/ | tail -1)

On the "find" command, I thought the -mmin would be any file that was modified within "n minutes", so like on the files above, a file that was modified/created within the last 40mins. Is that wrong?

Thanks again for the reply.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the absolute path of file using file descriptor. appas Programming 7 01-19-2012 12:47 PM
Write to a file in Linux with an absolute network path jsenar Linux - Newbie 1 09-07-2009 01:50 PM
What is the absolute path of mozilla component directory in RHEL 5.0 Red Hat Linux - Software 1 09-06-2007 05:48 PM
Tail Last Modified File in a Directory tyoungblood Linux - Software 3 08-12-2005 09:42 AM
Get directory stats when a file has been modified? marri Programming 2 05-13-2004 09:44 PM

All times are GMT -5. The time now is 04:37 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration