How to get the no of files from a particular directory in UNIX?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to get the no of files from a particular directory in UNIX?
# 1  
Old 04-16-2008
How to get the no of files from a particular directory in UNIX?

Hi,

i have one scenario that i want to count the no of files in the specified Directory.

if if put the

ls -rtl | grep "^d" --> Retreive the list of directory only
ls -rtl | grep "^-r" --> Retreive the list of files only

But i want to know if i pass the directory name i want to count the no of files are there in the dir

Let me know if need more details on this.

Thanks,
Siva.P
Bangalore
# 2  
Old 04-16-2008
If you pass the directory name to ls -ltr, it should work.

ls -ltr my_dir | grep "^d"
# 3  
Old 04-16-2008
one way
Code:
fullpath=/path/directory
find $fullpath -type f | wc -l 
find $fullpath -type d | wc -l

# 4  
Old 04-17-2008
find /path/directory -type f -print | wc -l
find /path/directory -type d -print | wc -l

Above commands is recursive by nature. You can limit it to current directory with option "-maxdepth 1".
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX :renaming the files present in the directory

Hi all, I am looking for a script which renames all the files from the present directory. Eg.: In unix directory contains the below files linux001.txt linux002.txt linux003.txt ...... ....... Now the files should be renamed to unix001.txt unix002.txt unix003.txt Could anyone... (8 Replies)
Discussion started by: scriptscript
8 Replies

2. UNIX for Dummies Questions & Answers

Listing files in a Unix Directory ending with .....

Hi Unix Gurus, I need to list all files in a Unix Directory which either end with a .pdf or .rtf and they should be case insensitive ie .Pdf , .pDF , .RtF etc are also possible. How can i accomplish this with with a ls command ? If not then a find command. (6 Replies)
Discussion started by: pchegoor
6 Replies

3. UNIX for Dummies Questions & Answers

Read all files in a directory for a unix command

Hello, Below, I have a unix command, which can be executable for single file. cat input.txt | sort -k3,3 > output.txt I have 100 input files in a directory. It is hectic and time taking to run the above command for all the 100 files for 100 times. Now, I want to execute the above unix... (2 Replies)
Discussion started by: koneru_18
2 Replies

4. UNIX for Dummies Questions & Answers

Copying files from unix servers to other locations e.g. C directory

Hi, I am just wondering is it possible to move or copy a file from a UNIX server to a different location e.g. the C drive on a computer? I have used the cp command to move files to different locations on unix servers but it would be handy to move a file to my C drive. I am currently... (3 Replies)
Discussion started by: crunchie
3 Replies

5. UNIX for Dummies Questions & Answers

Recover directory/files in unix

Hi Guys I accidently deleted a directory( and the files in it) in unix using 'rm -rf' :) Is there any procedure/script/command to recover the same? Your help is highly apperciated -thanks Subramanya (1 Reply)
Discussion started by: sgbhat
1 Replies

6. Shell Programming and Scripting

using c programming in unix to delete zero-byte files in a specified directory

we were asked to make a program that deletes all zero-byte files in a psecified directory. we need to use sysytem_calls like: scandir(),chdir(),stat() and remove(). (3 Replies)
Discussion started by: sogetsu009
3 Replies

7. Shell Programming and Scripting

tarring/compressing files in Unix directory

hi guys, i'm totally new with Unix sripting and no idea how to do the scripting at all. My problem is that my boss asked me to do this: 1.) create a script that will tar or gzip the files in particular directory eg: i'm on my home directory and I need to tar/gzip the file in.. assuming... (1 Reply)
Discussion started by: montski
1 Replies

8. HP-UX

Want to remove files from unix directory

Dear All I am basic user of Unix. i woul like to delete some files (basically 05 and 0801111105) from unix directories but unable to delete it I tried all option. rm , rm -f etc.. but not succeed. Infact it also not allowing me to use chmod option so that i can grant 777 option to... (1 Reply)
Discussion started by: yogi_chavan
1 Replies

9. UNIX for Dummies Questions & Answers

2048 files/directory in Unix Sco ?

I found my directories to be filled with 2048 files. The number of files per directory is not exceeding this number. Is this the default and what should i do to increase it? Regards (3 Replies)
Discussion started by: BAM
3 Replies

10. UNIX for Dummies Questions & Answers

moving files from a unix directory to a windows directory

Any body any ideas i'm failry new to this so any help would be appreciated. Cheers Steve (2 Replies)
Discussion started by: gleads
2 Replies
Login or Register to Ask a Question