I am hoping to be able to find the last modified file in a directory
and copy it to another directory under a different name. I have so far
been trying to find a way to use the 'find' command followed by the
'-exec'. Unfortuately I cannot find an option that finds the last
modified file.
I would be grateful to hear any suggestions.
|
|
0
|
|
|
|
Reply
|
mark
|
10/24/2006 5:01:49 PM |
|
On 24 Oct 2006 10:01:49 -0700, mark.pollard@cwfi.co.fk wrote:
>I am hoping to be able to find the last modified file in a directory
>and copy it to another directory under a different name. I have so far
>been trying to find a way to use the 'find' command followed by the
>'-exec'. Unfortuately I cannot find an option that finds the last
>modified file.
>
>I would be grateful to hear any suggestions.
If subdirectories aren't a concern, I would probably do something
like:
ls -1at /directory_in_question | while read a
do
[ -f /directory_in_question/"$a" ] && {
cp -p /directory_in_question/"$a" /wherever/whatever
exit 0
}
done
Note the numeral one, not an "el" in ls -1at.
Scott McMillan
|
|
0
|
|
|
|
Reply
|
Scott
|
10/24/2006 7:00:17 PM
|
|
In article <1161709309.276545.280600@m7g2000cwm.googlegroups.com>,
mark.pollard@cwfi.co.fk wrote:
>I am hoping to be able to find the last modified file in a directory
>and copy it to another directory under a different name. I have so far
>been trying to find a way to use the 'find' command followed by the
>'-exec'. Unfortuately I cannot find an option that finds the last
>modified file.
>
>I would be grateful to hear any suggestions.
>
cp "$(ls -tr | tail -1)" /destination/dir
Breaks if the most recent file has double quotes in its name.
--
Christopher Mattern
"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"
|
|
0
|
|
|
|
Reply
|
syscjm
|
10/24/2006 7:01:35 PM
|
|