How to copy the top 10 most recent files from one directory to another?

ThinkCode picture ThinkCode · May 15, 2012 · Viewed 18.3k times · Source

Al my html files reside here :

/home/thinkcode/myfiles/html/

I want to move the newest 10 files to /home/thinkcode/Test

I have this so far. Please correct me. I am looking for a one-liner!

ls -lt *.htm | head -10 | awk '{print "cp "$1" "..\Test\$1}' | sh

Answer

aphex picture aphex · May 15, 2012
ls -lt *.htm | head -10 | awk '{print "cp " $9 " ../Test/"$9}' | sh