Home > OS >  How would I list files which only have a specific amount of characters?
How would I list files which only have a specific amount of characters?

Time:10-27

If I have these files:

  • a.txt (50 characters)
  • b.txt (21 characters)
  • c.txt (46 characters)
  • d.txt (10 characters)
  • e.txt (21 characters)

What command can I use in the command line to only find files with a character count of exactly 21? In this case the command would return something like:
b.txt e.txt

CodePudding user response:

Here's one approach ...

stat -c "%s %n" *txt | awk '$1=="21"{print $2}'
b.txt
e.txt
  • Related