Quantcast
Channel: How can I get a count of files in a directory using the command line? - Unix & Linux Stack Exchange
Browsing latest articles
Browse All 22 View Live

Answer by WoodrowShigeru for How can I get a count of files in a directory...

To build on James' answer, you can write something like this to achieve a breakdown of all the direct subdirectories.tree -aFid -L 1 . | while read f; do if [[ -d "${f}" ]]; then echo -en "${f}: ";...

View Article



Answer by Stéphane Chazelas for How can I get a count of files in a directory...

With some shells, you can do that without relying on external utilities:fishcount *Or to include hidden files:count * .*zshDefine a function, here called count to mimic fish's builtin:count() print...

View Article

Answer by user14927127 for How can I get a count of files in a directory...

I use this one, few examples:ls -Ap directory01/directory02 | grep -v /$ | wc -lls -Ap directory01/directory02/exampl* | grep -v /$ | wc -lls -Ap /home/directory01/directory02 | grep -v /$ | wc -lIt...

View Article

Answer by Hopping Bunny for How can I get a count of files in a directory...

If you have rights to install packages, there is a very simple tool to do this (and more). It is called ncdu and it can be installed using apt or yum. A basic usage of ncdu would be:ncdu...

View Article

Answer by codeforester for How can I get a count of files in a directory...

On Linux, to make the command very robust and handle files that might have newlines in their name, use this:find -maxdepth 1 -type f -print0 | tr -cd '\0' | wc -cThis saves us from the ordeal of...

View Article


Answer by krlmlr for How can I get a count of files in a directory using the...

I have found du --inodes useful, but I'm not sure which version of du it requires. It should be substantially faster than alternative approaches using find and wc.On Ubuntu 17.10, the following...

View Article

Answer by Jonathan Prieto-Cubides for How can I get a count of files in a...

Improving some answers given before but this time doing explicitly.$ tree -L 1 | tail -n 1 | cut -d "" -f 3It's worthy to notice the use of some loved commands like tail and cut. Also, note that tree...

View Article

Answer by aude for How can I get a count of files in a directory using the...

With the GNU implementation of find:find -maxdepth 1 -type f -printf . | wc -c-maxdepth 1 will make it non-recursive, find is recursive by default-type f will include regular files only-printf . is a...

View Article


Answer by srpatch for How can I get a count of files in a directory using the...

find . -type f -maxdepth 1 | wc -l This can list only the files in current directory.

View Article


Answer by AMIC MING for How can I get a count of files in a directory using...

You can check with:ls -l | grep -v ^l | wc -l

View Article

Answer by Tiger for How can I get a count of files in a directory using the...

Try this i hope this answer will help you echo $((`ls -l | wc -l` -1 ))

View Article

Answer by Jbnair for How can I get a count of files in a directory using the...

While using ls/wc pair if we are adding -U it will be much faster (do not sort ).ls -AqU | wc -l

View Article

Answer by user115186 for How can I get a count of files in a directory using...

Use the tree command, just:tree

View Article


Answer by Frax for How can I get a count of files in a directory using the...

Probably the most complete answer using ls/wc pair isls -Aq | wc -lif you want to count dot files, and ls -q | wc -lotherwise.-A is to count dot files, but omit . and ...-q make ls replace nongraphic...

View Article

Answer by DaboD for How can I get a count of files in a directory using the...

No pipe, no string copy, no fork, just plain bash one liner$ fcount() { local f i=0; for f in *; do let i++; done; echo $i; }; fcount

View Article


Answer by lev for How can I get a count of files in a directory using the...

After installing the tree command, just type:treeIf you want hidden files too:tree -aIf you are using Debian / Mint / Ubuntu Linux, type the following command to install the tree command:sudo apt-get...

View Article

Answer by Dennis Williamson for How can I get a count of files in a directory...

Here's another technique along the lines of the one Gilles posted:word_count () { local c=("$@"); echo "${#c[@]}"; }file_count=$(word_count *)which creates an array with 13,923 elements (if that's how...

View Article


Answer by nicomen for How can I get a count of files in a directory using the...

ls -1 | wc -l...$ ls --help | grep -- ' -1' -1 list one file per line...$ wc --help | grep -- ' -l' -l, --lines print the newline countsPS: Note ls -<number-one> | wc -<letter-l>

View Article

Answer by Gilles 'SO- stop being evil' for How can I get a count of files in...

If you know the current directory contains at least one non-hidden file:set -- *; echo "$#"This is obviously generalizable to any glob.In a script, this has the sometimes unfortunate side effect of...

View Article

Answer by Maciej Piechotka for How can I get a count of files in a directory...

For narrow definition of file: find . -maxdepth 1 -type f | wc -l

View Article

Answer by James for How can I get a count of files in a directory using the...

Using a broad definition of "file"ls | wc -l(note that it doesn't count hidden files and assumes that file names don't contain newline characters).To include hidden files (except . and ..) and avoid...

View Article


How can I get a count of files in a directory using the command line?

I have a directory with a large number of files. I don't see a ls switch to provide the count. Is there some command line magic to get a count of files?

View Article

Browsing latest articles
Browse All 22 View Live




Latest Images