Tags
Twitter
- @karinalchemy @ChrisPenberthy No problem, glad to help! 2 hours ago
- @loudmouthman I think that the whole issue could be avoided if Facebook was private by default and you had to open up your profile yourself 2 hours ago
- @loudmouthman Good point, re electoral roll etc, I opt out wherever possible, but that's just me, I like to control my level of disclosure 2 hours ago
- @loudmouthman In fact, people still find me on facebook despite having most things set to "friends only" 3 hours ago
- @loudmouthman I was under the impression that opting out of public search listings didn't affect the ability of logged in users to find you 3 hours ago
Counting All Files in a Linux Directory
To count how many files there are in a directory using the terminal on a Linux machine you can combine 2 commands:
We’ll use the find command to locate all the files (and exclude directories and other non-files) and then the wc command to count the files.
Find has many options, but we will only be using the type option:
find . -type fThe . indicates the directory to search in and can be replaced with any absolute or relative path. This command will also find files in subdirectories. To exclude subdirectories you can use:
find . ! -name . -prune -type fThe
! -name . -prunewill ignore any directories that are not the current one.The find command will give us a list of all the files we want to count, to count the number of entries in that list we must pass the output to wc to count it.
By default, wc will count words, newlines, and bytes. Since the output from find is a list of files, each separated by a newline, we can tell wc to only count newlines by using the -l argument:
wc -lCombining this into a single command, we get the final command to find count the number of files in a directory excluding sub-directories:
find . ! -name . -prune -type f | wc -l(Of course, if you want to include sub-directories, simply remove the
! -name . -prunearguments and use:find . -type f | wc -linstead)