QuestionQ155Verified/Essential CommandsCopy linkReport a problemAsk AstroTutorSave questionWhich command chain will count the number of regular files named foo.txt located within /home?Als -lR /home | grep foo.txt | wc -lBfind /home -type f -name foo.txt | wc -lCfind /home -name foo.txt -countDfind /home -name foo.txt | wc -lEgrep -R foo.txt /home | wc -lShow AnswerAnswerExplanationThe find utility's -type f flag restricts results to regular files, and -name foo.txt matches files with that exact name. Piping the output to wc -l counts the resulting lines, giving an accurate count of regular files named foo.txt. This is documented behavior of the GNU findutils find command, where -type f is the standard way to filter for regular files as opposed to directories, symlinks, or other file types.Learn morefind(1) - Linux manual pageShow comments0Show commentsCommunity DiscussionNo comments yet. Be the first to start the discussion!
Community Discussion