Skip to content
Advertisement

Moving files with a specific modification date; “find | xargs ls | grep | -exec” fails w/ “-exec: command not found”

Iam using centos 7

If I want to find files that have specific name and specific date then moving these files to another folder iam issuing the command

find -name 'fsimage*' | xargs ls -ali | grep 'Oct 20' | -exec mv   {}  /hdd/fordelete/  ;

with the following error

-bash: -exec: command not found xargs: ls: terminated by signal 13

Advertisement

Answer

the -exec as you wrote it is quite meaningless, moreover it seems you are mixing find syntax with shell oe (-exec as you wrote it should be passed to find)

there are probably more concise ways of doing, but this should do what you expect:

 find  -name 'fsimage*' -type f  | xargs ls -ali  | grep 'Oct 20' | awk '{ print $NF }' | while read file; do  mv "$file" /hdd/fordelete/  ; done

nevertheless, you should take care of not just copy/paste things you do not really understand from the web, you may wreck you system…

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement