When I tried the limited files to another folder, the file format is .flv
. which is used the command :
ls -ltr | grep 'May 16 2013' | awk '{print $9}' | xargs cp -rf /root/directory/.
How can I do that?
When I tried the limited files to another folder, the file format is .flv
. which is used the command :
ls -ltr | grep 'May 16 2013' | awk '{print $9}' | xargs cp -rf /root/directory/.
How can I do that?
As GoodPerson mentioned, the easier way to do this is to use find
with exec
.
find . -name '*May 16 2013*' -exec cp -rf {} /root/directory \;
Observe that, in the command above, the command cp -rf {} /root/directory
will be executed for every file or directory found by find
, and where the directory is substituted into {}
.
Update: The command above assumes (probably incorectly) that your filename contains May 16 2013
. If you actually files that were modified on that date, the problem is a little more complicated and depends on your version of find
, but this answer tells us how to do it with older versions of find.
First, you create two reference files with dates that you specify. Then you find files that live in between those dates. The following three commands will find files on May 16 2014.
touch -d '16 May 2014' /tmp/Ref
touch -d '17 May 2014' /tmp/Ref2
find . -maxdepth 1 -newer /tmp/Ref -and -not -newer /tmp/Ref2
If you are satisfied with the result of find
, you can then append the exec
as I have above.