Some rogue process has created thousands of files with extension .foo in /tmp, filling up the entire filesystem. After you kill the process and remove the homedirectory of the user who started this process you want to clean up /tmp. But you get the following error:
rm: argument list too long
Which of the following commands will allow you to remove all *.foo files in /tmp ? (choose the best answer)
A.
rm `ls | grep ‘.foo$’`
B.
ls *.foo | xargs rm
C.
ls | grep ‘.foo$’ | xargs rm
D.
xargs rm `ls | grep ‘.foo$’`
Explanation:
xargs reads arguments from the standard input, delimited by blanks (which can be protected with double or single quotes or a backslash) or newlines, and executes the command (default is /bin/echo) one or more times with any initial-arguments followed by arguments read from standard input. Blank lines on the standard input are ignored. xargs exits with the following status:0 if it succeeds
123 if any invocation of the command exited with status 1-125
124 if the command exited with status 255
125 if the command is killed by a signal
126 if the command cannot be run
127 if the command is not found
1 if some other error occurred.