Solved

Find most recent file

Posted on 2013-06-17
4
521 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
  • 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 250 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 34

Assisted Solution

by:Seth Simmons
Seth Simmons earned 250 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now