Celeb Glow
updates | March 24, 2026

List files of particular extension

Ok this is strange. I am using this code,

ls *.prj

To list all the files with the .prj extension in the dir but I am getting this error,

bash: /bin/ls: Argument list too long

I eventually wish to get the count of files and I was using,

ls *.prj | wc -l

But even this command is giving the same error. Any idea where I am going wrong?

3 Answers

Use find command instead

 find . -name "*.prj"

You can also combine the commands with find

find . -name "*.prj" -exec COMMAND {} \;

Hope this helps.

4

Nothing, there is a limit on the number of argument bash can deal with. Do

ls | grep '\.prj$' | wc -l
1

Parsing the output of ls is unreliable. It will probably work in your case, but ls mangles unprintable characters. Here is a fully reliable way of counting the files matching a certain extension. This shell snippet creates an array containing the file names, then prints the number of elements in the array.

shopt -s nullglob
a=(*.prj)
echo ${#a[@]}
4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

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