I want to find and count all the files on my system that begin with some string, say "foo", using only one line in bash.
I'm new to bash so I'd like to avoid scripting if possible - how can I do this using only simple bash commands and maybe piping in just one line?
So far I've been using find / -name foo*
. This returns the list of files, but I don't know what to add to actually count the files.
If you want to count only files and NOT include symbolic links (just an example of what else you could do), you could use ls -l | grep -v ^l | wc -l (that's an "L" not a "1" this time, we want a "long" listing here). grep checks for any line beginning with "l" (indicating a link), and discards that line (-v).
The total number of items (both files and folders) stored inside is displayed in the lower-left corner of File Explorer's user interface. If you want to count only some of the files or folders stored inside your folder, select all of them and look at the bottom left side of the File Explorer interface.
View Properties Just locate the folder, or the subfolder, for which you need to count the subfolders or files, right-click on it, and then click on Properties from the context menu. You can also press ALT+Enter to open the Properties of a folder or a subfolder.
You can use
find / -type f -name 'foo*' | wc -l
-type f
to include only files (not links or directories).wc -l
means "word count, lines only." Since find
will list one file per line, this returns the number of files it found.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With