Shell – List files in a directory with a certain extension

shellwildcards

I created a file called ~/usrlibs.txt, which contains the number of files that begin with lib and end .a found in the /usr/lib directory.

I tried:

ls -l /usr/lib/lib .a | wc -w > ~/usrlibs.txt 

But this command is not working correctly.

What am I missing?

Best Answer

Do you mean list all files that start with lib and end with .a in /usr/lib, then print the wordcount with wc to usrlibs.txt?

ls -l /usr/lib/lib*.a | wc -w > ~/usrlibs.txt

should work. You just forgot to add a wildcard between your patterns.

Related Question