|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
[Solved] Finding the latest file in a directory
Hi All, I am using the below command to find the latest file in a dir: Code:
ls -tr $v_sftphomedir/$v_sourcefile |tail -1 or Code:
ls -t1 $v_sftphomedir/$v_sourcefile |head -1 and the outpur returned is below: Code:
/home/cobr_sftp/var/controllingload/Backup/Dbrwds_Div_1796050246.txt I need only the filename(Dbrwds_Div_1796050246.txt) and not path. Who do i fetch only the filename from it? Please help
Last edited by abhi_123; 11-15-2012 at 06:50 AM.. |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Hi abhi_123, Use sed. Add it at the end of the pipe chain: Code:
... | sed -e 's|^.*/||' |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
What OS are you using since your output is not what I would expect?
IMHO using ls without -l should not give the absolute path... |
|
#4
|
|||
|
|||
|
A simpler ways include: Code:
basename "$v_sourcefile" and when using POSIX compliant shells Code:
${v_sourcefile##*/}---------- Post updated at 08:08 ---------- Previous update was at 07:58 ---------- Quote:
|
| The Following User Says Thank You to Don Cragun For This Useful Post: | ||
vbe (11-15-2012) | ||
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
Quote:
Quote:
![]() |
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
thanks it worked
thanks all it worked.
![]() |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Finding the Latest file in a Dir | filter | Shell Programming and Scripting | 2 | 06-24-2011 11:54 AM |
| Move the latest or older File from one directory to another Directory | pp_ayyanar | Shell Programming and Scripting | 1 | 03-24-2010 03:22 PM |
| Copy the latest file from one directory to another | chandancsc | Shell Programming and Scripting | 3 | 08-07-2009 04:35 AM |
| finding latest file having timestamp on it..... | kaushik25 | Shell Programming and Scripting | 1 | 08-06-2007 10:35 PM |
| finding latest file in Unix | nick12 | UNIX for Dummies Questions & Answers | 2 | 03-05-2005 01:27 AM |
|
|