Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find most recent file

Posted on 2013-06-17
4
Medium Priority
?
531 Views
Last Modified: 2013-06-18
Find the most recent file (named test) in a directory (recursively through subdirectories) and copy the most recent "test" file to another directory (/tmp/test/.)
0
Comment
Question by:raaj4354
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Author Comment

by:raaj4354
ID: 39253660
find -type f -name test -exec ls -ltr {} \;

this gives me the file listing with the path at the end. I need to copy this file to another folder.
0
 
LVL 23

Accepted Solution

by:
nemws1 earned 750 total points
ID: 39253707
Found this with a quick web search:
find . -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" "

Open in new window


Did some testing and reading and it works well (if a bit slowly)
0
 
LVL 35

Assisted Solution

by:Seth Simmons
Seth Simmons earned 750 total points
ID: 39253948
nemws1 find command is correct
you could take it a step further and include the copy process

cp $(find . -type f -printf '%T@ %p\n' | sort -n | tail -1 | cut -f2- -d" ") <destination>
0
 
LVL 23

Expert Comment

by:nemws1
ID: 39254348
Good one seth2740!  Don't you love the power of UNIX?!  I teach high school kids IT and we're actually doing UNIX command line now.

I keep telling them ... you build the tool you want out of smaller tools (they're slowing getting it).
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

660 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