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?

  • 1
    What is your question? – cuonglm Jun 25 '14 at 19:02
  • I assume that is a typo: ls -l /usr/lib/lib .a should be ls -l /usr/lib/lib*.a? – chaos Jun 25 '14 at 19:13

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.


Your command ls -l /usr/lib/lib*.a | wc -w > ~/usrlibs.txt just counts the words of the output that ls -l generates.

I think what you search counting the word in those lib*.a files:

user@host:~# wc -w /usr/lib/lib*.a
    222 /usr/lib/libanl.a
     31 /usr/lib/libBrokenLocale.a
     24 /usr/lib/libbsd-compat.a
  54564 /usr/lib/libc.a
    298 /usr/lib/libc_nonshared.a
    832 /usr/lib/libcrypt.a
    206 /usr/lib/libdl.a
     24 /usr/lib/libg.a
      6 /usr/lib/libieee.a
  15842 /usr/lib/libm.a
     12 /usr/lib/libmcheck.a
   2681 /usr/lib/libnsl.a
  37214 /usr/lib/libpthread.a
     99 /usr/lib/libpthread_nonshared.a
   1537 /usr/lib/libresolv.a
    600 /usr/lib/librpcsvc.a
    984 /usr/lib/librt.a
    431 /usr/lib/libsupp.a
    164 /usr/lib/libutil.a
 115771 total

Try using 'find' instead of 'ls':

find /usr/lib -name "lib*.a" | wc -w > ~/usrlibs.txt

The wildcard: * in the phrase "lib*.a" will give you all files that start with 'lib' and end with '.a'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.