1

I'm trying to do a script that counts all the files in the system that have a name with a odd number of characters, only the name not the extension. somebody can help me? I've done this but it doesn't work

find /usr/lib -type f | cut -f 1 -d '.' | rev | cut -f 4 -d '/' | rev | wc -m 

with this I count all the characters of all file, but how do I count the number of character of one file ?

mockinterface
  • 14,452
  • 5
  • 28
  • 49

2 Answers2

0

The following awk command will print out the number of files with an odd number of characters in their name.

find /usr/lib -type f | awk -F/ '{gsub(/\.[^\.]*$/,"",$NF);if(length($NF)%2!=0)i++}END{print i}'
dogbane
  • 266,786
  • 75
  • 396
  • 414
0

Print all the file names with an odd number of characters,

find /usr/lib -type f | xargs -i basename {} | cut -d . -f 1 | grep -Pv '^(..)+$'

pipe to wc to count.

mockinterface
  • 14,452
  • 5
  • 28
  • 49