+5 votes
31 views
Count Files Folder Linux

in Linux/Unix by (551k points)
reopened | 31 views

1 Answer

+3 votes
Best answer

How to count files in Linux folders using WC
2 How to count files in Linux folders using Tree
3 How to count files in Linux folders using Find
4 How to count files in Linux folders using graphical interface

To stay up to date, remember to subscribe to our YouTube channel!
SUBSCRIBE ON YOUTUBE

 

When we work with any of the Linux distributions, it is normal that we must carry out a number of information, management, control or administrative activities and a very useful task is to be able to have clarity about how many files are in a folder, this allows us to determine whether or not the amount of information in that folder is necessary..

 

To keep track of what we have stored on our computer, it is necessary to Count Linux Folder Files on occasion, so we want to leave you with multiple ways in which you can know how many files are in a folder using commands. There are some ways to access these details and TechnoWikis will explain each one in a complete way.

 

 


How to count files in Linux folders using WC

 

Step 1

The WC (word count) command has been developed to allow the user to count words, lines and characters in a text file that we select, the usage syntax is as follows:
 wc [options] file(s) 
Step 2

The options that we can use with the WC command are:

 

  • -c, --bytes: print the byte count of the text.
  • -m, --chars: print the character count of the text.
  • -l, --lines prints the count of new lines in that file.
  • -L, --max-line-length : Allows you to print the maximum width of the display.
  • -w, --words: print the word count of the document.

 

Step 3

First of all, we are going to open the terminal, there we will use the “cd” command to go to the folder to review and then we execute the “ls -A” command to see all the contents of said folder:

 

image

 

Note
the -A parameter will list all files and directories including hidden files and directories.

 

Step 4

Now, we are going to count the number of files and directories by executing the following:
 ls | toilet -l 
image

 

step 5

It is now possible to generate this list of files and directories in long list format with the "-l" parameter:
 ls -l | toilet -l 
image

 

step 6

Another option to use is to exclude the special entries (.) from the current directory and (..) from the main directory, for this view we are going to execute the following:
 ls -A | toilet -l 
image

 

step 7

To count the hidden files in the main directory and the current directory we will execute the following:
 ls -a | toilet -l 
image

 


2 How to count files in Linux folders using Tree

 

Step 1

This is a special command which allows us to graphically see the structure of directories and files using the tree format, with this a better visualization of the organization of files and folders in the file system is accessed in a hierarchical way of our system, in case of not having this we can install it with the following command:
 sudo apt install tree 
image

 

Step 2

Now it is enough to execute the “tree” command to see the structure of the selected directory. At the bottom we see the number of directories and files.

 

image

 

Step 3

Now, in order to count and see the hidden files, we are going to execute the following:
 tree -a 
image

 

Step 4

There is another group of options that we can use in tree, such as:
  • -d: list only directories
  • -l : follow symbolic links as directories
  • -f : prints the full path prefix of the file
  • -x: only the current file system will be there
  • -R : run the tree again when the maximum directory level has been reached
  • --prune: remove empty directories from output
  • -q: print non-printable characters in the format '?'
  • -Q: quote filenames with double quotes
  • -p: prints the protection measures of each file
  • -u : allows to see the owner of the file or the UID number
  • -g – outputs the filegroup owner or GID number
  • -s: prints the size in bytes of the file
  • -h : print the size readably
  • -D: prints the date of the last modification
  • --device: print the identification number of the device to which the file belongs
  • -t: sort files by last modified time
  • -X : prints an XML representation of the selected tree
  • -J : prints a JSON representation of the tree

 


3 How to count files in Linux folders using Find

 

 

Step 1

This is another of the commands available to be able to count the files that are hosted in a folder, this command allows you to search for files and directories in the file system taking the criteria or criteria that we indicate, its usage syntax is as follows:
 find directory -options criteria 
Step 2

With find it is possible to search by factors such as:
  • Filename
  • file extension
  • directories
  • Files
  • file size
  • Modification date
  • User or group property

 

Step 3

To use this command, we can first execute the following syntax using the wc command alternately:
 find <directory> <options> | toilet -l 
image

 

Step 4

We see that the number of files in that folder is counted. If we want to count only files we will execute the following:
 find(folder) -type f | toilet -l 
image

 

step 5

Now, if we only want to know the number of directories we execute:
 find(folder) -type d | toilet -l 
image

 

step 6

Another advantage of this command is being able to search for files by a specific type of extension:
 find . -type f -name "*.extension" | toilet -l 
image

 

step 7

Another option to use is to resort to the "output redirection" function with which it is possible to redirect error messages, for this we are going to execute the following:
 find /etc -type f 2> /dev/null | toilet -l 
image
step 8

Finally it is possible to use special parameters with minimum and maximum values:
 find(Directory) -mindepth 1 -maxdepth 1 | toilet -l 
image

 


4 How to count files in Linux folders using graphical interface

 

Step 1

Finally, we can review or validate the number of files in a folder from its properties, for this method, we go to the desired folder, right-click on it and in the displayed options click on "Properties":

 

image

 

Step 2

Then, we can see under the name of the folder the details of the folder where the number of files that are stored there is indicated:

 

image

 

With all these methods it is possible to count the number of files in a folder in Linux and have full control over them..

 


by (3.5m points)
edited

Related questions

+5 votes
1 answer
asked Mar 5, 2020 in Windows 10 by backtothefuture (551k points) | 1.9k views
+4 votes
1 answer
asked Jul 6, 2023 in Linux/Unix by backtothefuture (551k points) | 40 views
+5 votes
1 answer
asked May 8, 2023 in Linux/Unix by backtothefuture (551k points) | 50 views
+3 votes
1 answer
asked Nov 21, 2022 in Security by backtothefuture (551k points) | 43 views
+5 votes
1 answer
asked Jun 20, 2020 in iPhone Tutorial by backtothefuture (551k points) | 208 views
Sponsored articles cost $40 per post. You can contact us via Feedback
10,634 questions
10,766 answers
510 comments
3 users