I want to run this command in background because the process could take a long time. How can I send it to a background process?
find /tmp/ -type f -mtime +3 | xargs rm -Rf
This does not work:
find /tmp/ -type f -mtime +3 | xargs rm -Rf &
How can I do this instead?
Best Answer
If you want to run both in background, put them in a subshell:
But, please, don't do this. Piping
find
output intoxargs
is unsafe unless you use the following options, which are supported in GNU and BSDfind
andxargs
:If
find
returned files with spaces in their name you could – without even knowing – irreversibly delete the wrong folders. Carefully read thefind
manual and the section about deleting files for more info.The safest way, in your case, would be: