Categories: Ubuntu

Count the Lines of all files in Directory Ubuntu

When you are running low on disk space, you can free up some space by finding out how many files are in a specific directory, thereby determining which directories occupy most disk space.

This guide will focus on using various commands and techniques to determine the number of files in a specific directory.

Wc command

The simplest method to calculate the number of files in a directory is to use the wc command. For example, using find and wc, we can get the total number of files as shown in the command below:

find
Sponsored
/etc/ -maxdepth 1 -type f | wc -c

The command above will recursively find the files in a specific directory. To include the directories, use the ls command and pass the output to wc.

ls -l /etc | wc -l

NOTE: Using ls without arguments might result in a different value as wc counts the number of lines printed out.

The tree command

Another tool we can use to get the number of files in a directory is the tree command. A tree is a simple utility that shows the files and directories in forest format.

To install the tree on Debian systems, use the command:

sudo apt-get install tree

To count the number of files in a specific directory with a tree, use the command:

tree -L 1 /etc | grep files

Sponsored

As seen, a tree shows both the total number of files and directories.

To show hidden files, use the -a option to include all the files:

tree -a -L 1 /etc | grep files

Nautilus

You can also use the Graphical interface to show the number of files in a directory. This method may give different results depending on the file manager you are using.

In Ubuntu, navigate to the target directory, right-click, and select properties. In the contents section, you will see the total number of files and directories. For example:

Conclusion

In this quick tutorial, we discussed how to count the number of files in a specific directory in Linux using the wc command, tree, and the graphical interface.

Ubuntu Server Admin

Recent Posts

VirtualBox 7.2.2 Fixed TPM 2.0 Emulation & KVM Conflict

Oracle VirtualBox, announced the first maintenance update for the 7.2 release series few days ago.…

11 hours ago

Firefox 143.0 is out with Microsoft Copilot AI Integration

Firefox 143.0, the new monthly release of the popular free open-source web browser, is available…

11 hours ago

VLC 3.0.22 Adds Qt6 & AMD AI Frame Interpolation Support [Ubuntu PPA]

VLC, the popular free open-source media player, rolled out the new 3.0.22 version few days…

11 hours ago

Dash to Panel updated with GNOME 49 (Ubuntu 25.10) Support

Dash to Panel, the popular Gnome Shell extension, updated few days ago with support for…

1 day ago

Ubuntu Weekly Newsletter Issue 909

Welcome to the Ubuntu Weekly Newsletter, Issue 909 for the week of September 7 –…

2 days ago

Canonical announces it will support and distribute NVIDIA CUDA in Ubuntu

Today Canonical, the publisher of Ubuntu, announced support for the NVIDIA CUDA toolkit and the…

2 days ago