Du without directory and Grep for occurrences of a word

Assistance on work Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!

  1. The problem statement, all variables and given/known data:

Files stored in /bin, /sbin, /usr/bin, and /usr/sbin vary in their respective sizes. In fact, there are 244 different sizes if we do not count the zero byte files. Create a command line that proves this and stores the answer, 244, in a files named sizes.txt.

On how many lines does �state� (in any case) appear in any and all of the files in /usr/dict/? Your answer should be a total, not a count per file

  1. Relevant commands, code, scripts, algorithms:
    See below?

  2. The attempts at a solution (include all code and scripts):

  1. du -a /{,usr/}{,s}bin | sort -nu | grep -v ^0 | wc -l > ~/sizes.txt
  2. 248

I am close but i cant figure out how or why it counts the directories themselves

grep -i "state" /usr/dict/* | wc -l
-- 731
grep -i " state " /usr/dict/* | wc -l
-- 45
grep -i "\<"state"\>" /usr/dict/* | wc -l
--110

These all give me different counts...i know some are looking for just the word state and others occurrences of "state" but i when i do occurrences of "state" its not everyone of them...

  1. Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
    KeeneStateCollege(KSC), Keene(NH), USA, Charlie W., CS-215-01 Unix

Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).

As far as the first question is concerned:

find /{,usr/}{,s}bin -type f -exec du {} + | 
  awk 'END { 
    print c 
    }
  $1 && !_[$1]++ { 
    c++ 
    }'

With GNU awk:

find /{,usr/}{,s}bin -type f -exec du {} + | 
  awk 'END { 
    print length(_) 
    }
  $1 { _[$1] }'
1 Like