0

I am using the bash ls command as follows:

ls -S -l *usc*.vhd

This lists all the files that have the letters usc in its name and ends with .vhd extension. Now, I also need the output to print how many lines there are in each file. Is this possible in bash? I will need to use wc command of bash in some way but don't know how.

quantum231
  • 2,420
  • 3
  • 31
  • 53

1 Answers1

1

Use find with exec param instead of ls command:

find . -type f -name "*usc*.vhd" -exec wc -l {} \;
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105
  • OK, now that this is giving me number of lines along with file name, how do I pipe this into sort command so they file with the most lines comes out at the top? – quantum231 Feb 20 '23 at 13:39
  • 1
    @quantum231, pipe it to `| sort -rn` – RomanPerekhrest Feb 20 '23 at 13:43
  • I am getting the result I need so this questions has been answered. So thanks for that. What does \; do? First I thought maybe I need to put sort in its place, but this is not required. I am able to put the pipe after the \; – quantum231 Feb 20 '23 at 13:59
  • `\;` (or `";"` or `';'`) just passes a literal semicolon to `find` so that it knows where your `-exec` ends. You have to escape it to prevent bash from treating it as bash syntax. – tjm3772 Feb 20 '23 at 14:25