• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 534
  • Last Modified:

Find most recent file

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
raaj4354
Asked:
raaj4354
  • 2
2 Solutions
 
raaj4354Author Commented:
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
 
nemws1Database AdministratorCommented:
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
 
Seth SimmonsSr. Systems AdministratorCommented:
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
 
nemws1Database AdministratorCommented:
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
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

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now