search
HomeComputer TutorialsComputer KnowledgeHow to count the number of files in a directory on Linux

How to count the number of files in a directory on Linux

Mar 20, 2024 pm 05:16 PM
documentTable of contentscalculate

How to count the number of files in a directory on Linux

If you are using an operating system, you must count the number of files available in a directory as it provides a brief overview of the contents. It allows you to limit storage space and get details of unnecessarily large files. Additionally, as a Bash script user, you can count the number of files to automate specific tasks and limit the number of them.

However, many beginners want to know how to check the number of files. Therefore, we provide several commands on the blog that can help them quickly count the number of files available in a directory.

How to count the number of files in a directory on Linux

Let us divide this guide into multiple sections, in which we will explain the different commands to count the number of files in Linux.

1. Wc command
You can use the "wc" command and "ls" to check the number of files in the directory. For example, let's count the number of files available in Downloads.

LS. | WC—L

The "-l" option instructs to count lines instead of words. If you want to count hidden files, use the "-a" option.

LS—a| WC—L

Counting specific types of files is also easy as you just need to run the following command. For example, let's count ". js" files:

ls *.js| WC—L

To count all visible and hidden files in a directory, you can also use the following command:

Found.—Type F|WC—L

Note: The previous command includes hidden files.

2. Tree command
The "tree" command is useful when working with nested subdirectories because the command provides explicit information about the files. Additionally, the tree also shows a summary at the end, including the number of files. If your system does not have the "tree" utility, run the following command:

Sudo apt installation tree (Ubuntu)
sudo dnf install tree (Fedora)
SUDO YUM installation tree (based on RHEL operating system)

Note: By default, the "tree" command is recursive, which means that the output can include all subdirectories.

Tree

Since the previous command does not include hidden files, run the following command to display them:

tree—a

in conclusion

It's all about multiple ways of counting files in a directory. Remember that counting the number of files in a directory can help you perform routine system checks and storage cleanup. You should use the "tree" command to get brief information on a directory.

The above is the detailed content of How to count the number of files in a directory on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:每日运维. If there is any infringement, please contact admin@php.cn delete
Download Hidester VPN/Proxy to Access Your Favorite Content - MiniToolDownload Hidester VPN/Proxy to Access Your Favorite Content - MiniToolApr 22, 2025 am 12:50 AM

Learn about Hidester VPN and Hidester proxy and download Hidester VPN for Windows, Mac, Android, and iOS to use this VPN service to view websites with no limit. For more useful free computer tools and troubleshooting tips, you may visit php.cn Softwa

Windows Keyboard Opening Shortcuts Instead of Typing [Fixed]Windows Keyboard Opening Shortcuts Instead of Typing [Fixed]Apr 22, 2025 am 12:48 AM

Have you ever encountered the trouble of “Windows keyboard opening shortcuts instead of typing”? In this post from php.cn, you will learn how to fix this issue.

Easy Ways to Add the Control Panel Icon to Desktop on Win 10 / 11Easy Ways to Add the Control Panel Icon to Desktop on Win 10 / 11Apr 22, 2025 am 12:46 AM

In this post, php.cn Software will introduce what Control Panel is and how to add the Control Panel icon to desktop on your Windows 10 or Windows 11 computer. You can also learn some related information about desktop icon settings.

Granblue Fantasy Relink Save File Location & Backup Save DataGranblue Fantasy Relink Save File Location & Backup Save DataApr 22, 2025 am 12:45 AM

If you play Granblue Fantasy: Relink on your PC, you may wonder where you can find its save file. In this post, php.cn introduces everything you want to know - Granblue Fantasy Relink save file location and how to back up the savegame of this game.

How to Fix Event ID 1104: The Security Log Is Now Full? - MiniToolHow to Fix Event ID 1104: The Security Log Is Now Full? - MiniToolApr 22, 2025 am 12:44 AM

Event Viewer keeps track of activity for better management. However, if the upper limit of the security log is reached, no more events can be logged. In this post on php.cn Website, we will show you how to deal with Event ID 1104 the security log is

Watch: How to Enable Secure Boot on Gigabyte Motherboard?Watch: How to Enable Secure Boot on Gigabyte Motherboard?Apr 22, 2025 am 12:43 AM

Secure Boot is a security standard that can prevent your computer from booting with untrustworthy software. Enabling it will add an extra layer of security to your device. In this post from php.cn Website, we will show you how to enable Secure Boot o

Windows 11 23H2 Release Date: September 26, 2023 - MiniToolWindows 11 23H2 Release Date: September 26, 2023 - MiniToolApr 22, 2025 am 12:42 AM

Coming to a new year, what Windows 11 users are looking forward to are not only the patch updates but also the annual major update for Windows 11. This post will talk about the Windows 11 23H2 release date. In addition, if you want to recover deleted

How to Turn off Bixby on Samsung Phone? See a Guide! - MiniToolHow to Turn off Bixby on Samsung Phone? See a Guide! - MiniToolApr 22, 2025 am 12:41 AM

Can you completely disable Bixby? How to turn off Bixby on Samsung phones? It is not hard to disable this voice assistant. In this post from php.cn, we will go to any length to help you find the method. Besides, a way to turn off “Hi, Bixby” is also

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools