Linked Questions
13 questions linked to/from Is there a bash command which counts files?
-2 votes
1 answer
1k views
Check if directory exists and count files matching a pattern in it [duplicate]
My code has a directory path incoming, e.g., $D_path from a source. Now I need to check if the directory path exists and the count of files with a pattern (*abcd*) in that path exists or not in an IF ...
0 votes
1 answer
1k views
BASH: How to find the number of files in a directory and assign that number as a variable? [duplicate]
I am using BASH to attempt to automate a very tedious manual scanning process. I am very new to scripting and am learning as I go, but I've been googling and reading manuals for a day and a half and ...
-1 votes
2 answers
457 views
How to count .sh files [duplicate]
I have to count all executable files- done it and count files which are .sh files- no idea how to do it. Any help? Here's my code: c=0 d=0 for f in /home/lenovo/*; do if [ -x "$f&...
2 votes
0 answers
119 views
Until loop not working, script continuing on [duplicate]
I have a script that generates a .log file when the job finishes. I do not want it to move on until the number of .log files equals the number of .com files. Currently, if I execute this script it ...
-1 votes
1 answer
85 views
How to count how many files are in a directory via script [duplicate]
i am a new user and I was trying to build a script with which i can count how many files are in a direcotry, i did this but it does not seem to work. #! /bin/bash read -p 'path: ' dir dir=$dir if [ &...
543 votes
1 answer
961k views
Count number of files within a directory in Linux? [closed]
To count the number of files in a directory, I typically use ls directory | wc -l But is there another command that doesn't use wc ?
19 votes
7 answers
13k views
Sorting file names by length of the file name
ls displays the files available in a directory. I want the file names to be displayed based on the length of the file name. Any help will be highly appreciated. Thanks in Advance
6 votes
3 answers
13k views
How can I create a file with null bytes in the filename?
For a security test, I need to pass a file that contains null characters in its content and its filename. For the body content, it's easy to use printf: $ printf "Hello\00, Null!" > containsnull....
6 votes
3 answers
2k views
Counting total files in directory - find vs ls
Is there a reason why find . -mindepth 1 -maxdepth 1 | wc -l is suggested against ls -1 | wc -l (or vice-versa ?) to count the total number of files/directories inside a folder Notes: This ...
3 votes
2 answers
3k views
Output of ls | wc -l
Normally the output of wc -l command gives the number of lines in a file. But, when we pipe the output of ls command to it, it seems to show the number of files and directories and links in the ...
-2 votes
1 answer
2k views
How to get count of all the files of different extension type present in a directory and all its subdirectories using shell script
I need to count all the files present in a directory and all its subdirectory with specific file extensions using shell script. Ex: I want a count of all the .py and .sh files in a directory and its ...
3 votes
5 answers
296 views
What's the fastest way to count files?
We just installed a mass filer device that we want to store data from our suppliers on. They FTP files to it every day and right now, we've about 60,000+ files. Doing find . -name '*TXT' -exec ls '{}'...
2 votes
1 answer
153 views
Execvp works with "ls -l | wc" and failed with "ls -l|wc
I am writing a shell and currently implementing the pipe process. I am able to run "ls -l | wc", but when running "ls -l|wc" the process fails. I have tried debugging with gdb but unable to make ...