0

How can I copy the 2 most recent updated files from a directory? I'v searched for a while now and I can't seem to find it..

If anyone can help me I would really appreciate that!

Tristanz
  • 17
  • 3

2 Answers2

0

You can use this

rsync `ls -tp | grep -v / | head -n 2` <destination> <options>

Just make changes in appropriate places and it'll work.

Jatin Luthra
  • 176
  • 1
  • 10
0
for i in `ls -rt | tail -n2` ; do cp $i <dest> ; done

ls -rt sorts the files in reverse order on the basis of modification time.

Vikas Tiwari
  • 517
  • 5
  • 16