I want to move the last 3 modified files from a directory using bash commands. However, I noticed that I can use find
in the following way:
find . -type f -mtime -0.5 -print -exec mv {} /home/user/Desktop \;
But I haven't figured out how to do the same with ls -tr | tail -n 3
. For example, this doesn't work:
ls -tr | tail -n 3 -exec mv {} /home/user/Desktop
tail: invalid option -- 'e'
The only reason I'd prefer to use the second option is in order to specify a number of files instead of an approximate time. Is it possible to make it work with ls
and tail
Thanks!