How to get number of files and directories?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to get number of files and directories?
# 1  
Old 11-15-2010
MySQL How to get number of files and directories?

Hi All,

can you please tell me how to get no.of files and directories in the given directory.Smilie
# 2  
Old 11-15-2010
sub_directory count in current directory
Code:
ls -l | grep "^d" | wc -l

file count in in current directory
Code:
 
ls -l | grep -v "^d" | wc -l

# 3  
Old 11-23-2010
The below would give you the exact file count.

PHP Code:
ls -lrt grep "^-r" 
# 4  
Old 11-23-2010
The directory may contain special files or links.
I suggest using:
Code:
ls -lA  | grep -c "^d"

for directories

and
Code:
ls -lA  | grep -c "^-"

for files

ciman

Last edited by Scott; 11-23-2010 at 02:33 PM.. Reason: Code tags
# 5  
Old 12-12-2010
Files and directories:
Code:
( set -- *; echo $# )

Directories:
Code:
( set -- */; echo $# )

 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Archiving and moving files into directories, creating directories, etc.

how can i move "dataName".sql.gz into a folder called 'database' and then move "$fileName".tar.gz * .htaccess into a folder called 'www' with the entire gzipped file being "$fileName".tar.gz? Is this doable or overly complex. so mydemo--2015-03-23-1500.tar.gz > database -... (5 Replies)
Discussion started by: wyclef
5 Replies

2. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 Replies

3. Shell Programming and Scripting

Script to count number of files in directories

Hi All! I would like to have a script that will count the number of files at the top of the hour of soome directories and mail the results to me. I was thinking on : a=`/directory/subdirectory/ | wc -l` echo "/directory/subdirectory :$a" b=`/another_dir/subdir/ | wc -l` echo... (12 Replies)
Discussion started by: fretagi
12 Replies

4. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

Can anyone come up with a unix command that lists all the files, directories and sub-directories in the current directory except a folder called log.? Thank you in advance. (7 Replies)
Discussion started by: Manjunath B
7 Replies

5. UNIX for Dummies Questions & Answers

Number of files in all (sub-)directories

Hi, I need a list of the number of files in all (sub-)directories e.g.: /a/b/c 1364 /a/b 125 /a 362 etc. Should be nice to have the list sorted from high to low. Regards, Wim (6 Replies)
Discussion started by: deleriumdog
6 Replies

6. Shell Programming and Scripting

Need help with examine the number files in directories given as arguments

Hi , this is homework .. I have to finish it tomorrow, I did my best , but I found it so difficult .. Can You HELP Me ??! Write a bash shell script filestatic. The script should examine the number files in directories given as arguments (parameters) to this script. a. if one argument is... (1 Reply)
Discussion started by: abo-el-sos
1 Replies

7. UNIX for Dummies Questions & Answers

List directories and sub directories recursively excluding files

Hi, Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process. I wanted to disply using a unix command all the directories recursively excluding files. I tried 'ls -FR' but that display files as... (3 Replies)
Discussion started by: pointers
3 Replies

8. Shell Programming and Scripting

Help with command to Move files by X number to seperate directories

Hello, I need help finding a script that will allow me to move files from one directory to another directory 10k files at a time. I have a directory that has 100 K files in it. I need to have those 100k files broken apart to separate directories each with 10k files in them. Here is the... (8 Replies)
Discussion started by: Geo_Bean
8 Replies

9. Shell Programming and Scripting

Bash scripting to compare N number of files located in two directories

I want to compare "N" (around 2000+) number of huge files located in a directory A against "N" files located in a different directory using Bash scripting. Please help me with any scripts available. Thanks. (2 Replies)
Discussion started by: Sangtha
2 Replies
Login or Register to Ask a Question