Solved

Find most recent file

Posted on 2013-06-17
4
525 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
Fine Tune your automatic Updates for Ubuntu / Debian
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
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.

821 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