I am able to locate files in a folder containing a specific text string using this command:grep -lir 'string' ~/directory/*How do I move the files that appear in the above result to another location?
Grep command to find files containing text string and move them
grep
As always, beware of grep -r. -r is not a standard option, and in some implementations like all but very recent versions of GNU grep, it follows symbolic links when descending the directory tree, which is generally not what you want and can have severe implications if for instance there's a symlink to / somewhere in the directory tree.In the Unix philosophy, you use a command to search directories for files, and another one to look at its content.Using GNU tools, I'd do:xargs -r0 --arg-file <(find . -type f -exec grep -lZi string {} +  ) mv -i --target-directory /dest/dirBut even then, beware of race conditions and possible security issues if you run it as one user on a directory writeable by some other user.