Al my html files reside here :
/home/thinkcode/myfiles/html/
I want to move the newest 10 files to /home/thinkcode/Test
I
ls -lt *.html | head -10 | awk '{print $NF}' | xargs -i cp {} DestDir
In the above example DestDir
is the destination directory for the copy.
Add -t
after xargs to see the commands as they execute. I.e., xargs -i -t cp {} DestDir
.
For more information check out the xargs command.
EDIT: As pointed out by @DennisWilliamson (and also checking the current man page) re the -i
option This option is deprecated; use -I instead.
.
Also, both solutions presented depend on the filenames in questions don't contain any blanks or tabs.