User Tools

Site Tools


how_to_count_all_the_files_in_a_directory

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
how_to_count_all_the_files_in_a_directory [2016/08/03 23:46] – created walkeradminhow_to_count_all_the_files_in_a_directory [2023/03/09 22:35] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== How to count all the files in a directory ====== ====== How to count all the files in a directory ======
 +<color darkorange>2016</color>
 +
 +----
 +Updated <color darkorange>Jun 2017</color>
 +----
 +To find all of the files in a folder or directory, use:
 \\  \\ 
 +    find . -type f | wc -l
 +\\ 
 +The <color #ed1c24>-type f</color> means files
 +\\ 
 +\\ 
 +To find all the sub directories, use:
 +    find . -type d | wc -l
 +\\ 
 +The <color #ed1c24>-type d</color> means directories. <color #ed1c24>Please Note:</color> The directory you are searching in is counted, so even with no sub directories, the count will be 1.
 +\\ 
 +\\ 
 +\\ 
 +\\ 
 +
 +----
 +Old
 +----
 +
 \\  \\ 
     ls -l -R /path | wc -l     ls -l -R /path | wc -l
 \\  \\ 
 \\  \\ 
 +Or:
 +\\ 
 +    find "/home/charles/testarea" -daystart -type f -mtime +6 | wc -l
 +\\ 
 +\\ 
 +Or:
 +\\ 
 +\\ 
 +#Delete subfolders from "/home/charles/testarea"\\ 
 +\\ 
 +#clear terminal window\\ 
 +echo -e "\033c"\\ 
 +\\ 
 +find "/home/charles/testarea" -mindepth 1  -mtime +6 -type d  | while read x; do echo "---------" ; echo Deleting folder "$x" ; rm -R "$x";
 +\\ 
 +\\  
 +done
  
how_to_count_all_the_files_in_a_directory.1470264374.txt.gz · Last modified: 2023/03/09 22:35 (external edit)