Get the file count in a folder


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the file count in a folder
# 8  
Old 03-25-2011
Quote:
Originally Posted by dinjo_jo
Use this command this is the fastest , even faster than find.

Code:
 ls -lR . | egrep -c '^-'

Thanks dinjo_jo,

This gives me the same output as my original code.

Quote:
Originally Posted by dinjo_jo
The reason for difference is output in find and ls is ignoring hidden files.

I was thinking in something like that could explain, but I wasn't sureSmilie

Regards
# 9  
Old 03-25-2011
Quote:
Originally Posted by cgkmal
[COLOR=Navy]Hi Kurumi,

In order to learn, may you show how it looks a socket, pipe and other different elements in a ls -lR print?
you can make a pipe for example like this
Code:
mkfifo fifo_pipe

try it and do a ls -l and see what letter it holds
# 10  
Old 03-25-2011
Both works great.
I wanted to include directories and hidden files as well.
So find works best for me.

Code:
find .|grep "^./"|wc -l
ls -lR . | grep ^[-d]|wc -l

# 11  
Old 03-25-2011
Quote:
Originally Posted by kurumi
you can make a pipe for example like this
Code:
mkfifo fifo_pipe

try it and do a ls -l and see what letter it holds

Hi kurumi,

Thanks! I've tested and know I see that printed lines could begin with "p" too, and some other symbols as "-".

With "man ls" I can see the options of the "ls" command but not the print out description and all its options.

Do you know where can I see that?


Thanks again
Quote:
Originally Posted by un1xl0ver_rwx
Both works great.
I wanted to include directories and hidden files as well.
So find works best for me.
ls -lRa show all and
Code:
ls -lRa | awk '$0~/^-/{print}' | wc -l

Gives me now the same output as "find . type f" showsSmilie

Regards
# 12  
Old 03-25-2011
@cgkmal, there are more information from coreutils info.
Code:
info coreutils 'ls invocation'

This User Gave Thanks to kurumi For This Post:
# 13  
Old 03-26-2011
Quote:
Originally Posted by kurumi
@cgkmal, there are more information from coreutils info.
Code:
info coreutils 'ls invocation'


Many thanks kurumi, I have it now!
.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Searching for file types by count in specific folder in RHEL 6

So I'm trying to search for the top 10 or 15 items under a directory by file type. I want to run a command on a directory and get something like the following: Example of expected output.. .PDF: 100, .txt: 95, .word: 80.. What would be the best way of going about this? I've searched around... (2 Replies)
Discussion started by: shackle101
2 Replies

2. UNIX for Dummies Questions & Answers

To delete the oldest files in a file when file count in the folder exceeds 7

Hi All, I need to delete the oldest file in folder when the file count in the folder exceed 6 ( i have a process that puts the source files into this folder ) E.x : Folder : /data/opt/backup 01/01/2012 a.txt 01/02/2012 b.txt ... (1 Reply)
Discussion started by: akshay01987
1 Replies

3. Shell Programming and Scripting

want to move set of file from one folder to another folder

Hi all, let me explain my requirments i am having 5 folder with different name for eg) abc , cdf , efd, rtg, ead each 5 folders contain 15 files i want to move 10 files to some other folder, remain 5 files should be there in the same folder. give me some suggestion on this. (6 Replies)
Discussion started by: natraj005
6 Replies

4. UNIX for Dummies Questions & Answers

Separate text files in a folder by word count

Hi, been searching Google for like an hour and I doubt I got the right keywords so might as well ask here. What I need: Before: Article1.txt 564 Article2.txt 799 Article3.txt 349 Article4.txt 452 * Separate files over 400 wordcount * After: Article1.txt 564... (3 Replies)
Discussion started by: Richard2000
3 Replies

5. UNIX for Dummies Questions & Answers

How to obtain a count of files in a folder and it's subfolders

First of all, the extent of my unix knowledge is next to nil. I've been able to telnet to a unix box, and thanks to the Computer Hope website, I've been able to learn a few basic commands to navigate from folder to folder, and view contents. What I really need to do is obtain a count of all... (2 Replies)
Discussion started by: scarfinv
2 Replies

6. Shell Programming and Scripting

Count matching filenames in a folder

Hi all, I have 4 files for example named abc01012009.txt abc02012009.txt abc03012009.txt abc04012009.txt in a folder. I would like to firstly backup the latest file available, in this case, the latest date available, abc04012009.txt to its subfolder named backup, and then rename the... (4 Replies)
Discussion started by: tententen
4 Replies

7. Shell Programming and Scripting

File Management: How do I move all JPGS in a folder structure to a single folder?

This is the file structure: DESKTOP/Root of Photo Folders/Folder1qweqwasdfsd/*jpg DESKTOP/Root of Photo Folders/Folder2asdasdasd/*jpg DESKTOP/Root of Photo Folders/Folder3asdadfhgasdf/*jpg DESKTOP/Root of Photo Folders/Folder4qwetwdfsdfg/*jpg DESKTOP/Root of Photo... (4 Replies)
Discussion started by: guptaxpn
4 Replies

8. Shell Programming and Scripting

Getting Sum, Count and Distinct Count of a file

Hi all this is a UNIX question. I have a large flat file with millions of records. col1|col2|col3 1|a|b 2|c|d 3|e|f 3|g|h footer**** I am supposed to calculate the sum of col1 1+2+3+3=9, count of col1 1,2,3,3=4, and distinct count of col1 1,2,3=c3 I would like it if you avoid... (4 Replies)
Discussion started by: singhabhijit
4 Replies

9. UNIX for Dummies Questions & Answers

command to get count in unzipped folder

Hi All, Is there is a way to do this in a single unix command I have unzipped some files into a directory .. I want to check the count of the files in the directory and also i need to check whether the files is having read permision or not.. I know it can be done by a script isthere... (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

10. Shell Programming and Scripting

Parse the .txt file for folder name and FTP to the corrsponding folder.

Oracle procedure create files on UNIX folder on a regular basis. I need to FTP files onto windows server and place the files, based on their name, in the corresponding folders. File name is as follows: ccyymmddfoldernamefile.txt; Folder Name length could be of any size; however, the prefix and... (3 Replies)
Discussion started by: MeganP
3 Replies
Login or Register to Ask a Question