Try deconstructing your pipeline to see what is happening.
find . -type f -name '*.mov' -print0 | xargs -0 ls -dtl | head -20 |
gives you a list of 20 newest mov
files. The lost looks like:
-rw-r--r-- 1 ljm users 12449464 Jan 10 16:24 ./05ED-E769/DCIM/215___01/IMG_5902.mov
-rw-r--r-- 1 ljm users 14153909 Jan 10 16:00 ./05ED-E769/DCIM/215___01/IMG_5901.mov
-rw-r--r-- 1 ljm users 13819624 Jan 10 15:58 ./05ED-E769/DCIM/215___01/IMG_5900.mov
So, your xargs|cp
will get this as input.
It will be
cp -rw-r--r-- 1 ljm users 13819624 Jan 10 15:58 ./05ED-E769/DCIM/215___01/IMG_5900.mov /Volume/New_Directory/
If we look at your error message,
cp: illegal option -- w
cp -r
is ok, cp -rw
will produce this message. So that is consistent with what I said.
So, the question is why the -l
in the copy. If you remove the long format, you get exactly what you need.
As a side note why ls -d
, if your find
ensures -type f
?
find . -type f -name '*.mov' -print0 | xargs -0 ls -t | head -20 | xargs -I{} cp {} /Volume/New_Directory/
should do what you want, but remember that you are parsing the output of ls
, which is considered not a good idea.
Personally, I would
find . -type f -printf "%T@ %p
" |
sort -n |
cut -d' ' -f 2- |
tail -n 20 |
xargs -I{} cp {} /Volume/New_Directory/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…