Total number of files in the folder should be listed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Total number of files in the folder should be listed
# 1  
Old 09-06-2013
Total number of files in the folder should be listed

Hi All,

When i give the ls -lrt to list out all files with total number of files , i get the output as
Code:
ls -lrt
total 72
-rw-r--r--    1 hari  staff           796 Jul 11 09:17 va.txt
-rw-r--r--    1 hari  staff           169 Jul 13 00:20 a.log
-rwxr-xr-x    1 hari  staff           659 Aug 10 04:45 final.sh
-rw-r--r--    1 hari  staff            98 Aug 10 04:48 noprob.txt
-rw-r--r--    1 hari  staff          3597 Aug 10 04:48 main.xls
-rw-r--r--    1 hari  staff           299 Aug 10 04:48 mailbody.txt
-rw-r--r--    1 hari  staff          4981 Aug 10 04:48 attachment.txt

Now our expectation is we should get the "total" number of files with only the filenameswhich was at the end like va.txt,a.log,final.sh etc.

I tried with ls -lrt|grep total to get the total line but am unable to get only the filenames by leaving the permission, user name, group, date and all.. Am requesting some help to complete this task as you were all in the part of my previous automations. Kindly do the needful friends.
# 2  
Old 09-06-2013
try sth like this

Code:
ls -lrt *.txt *.out

# 3  
Old 09-06-2013
Code:
ls *va.txt *a.log *final.sh | wc -l

The above command counts the number of files ending with the patterns listed.
# 4  
Old 09-06-2013
thanks for the prompt response

Hi, Thanks

I will be receiving different fileextensions like *.MOB *.TXT *.VBS *.MI so am unable to judge what kind of extension it may have sometimes it wont have an extension to find out. so at that situation i think the above ideas will be collapsed.

i gave the code like ls -1 it listed out only the filename. So when i give the command like ls -lrt|ls -1 its displaying only the filename without the total count. So is there any other way to retrieve only the filenames along with the total number of files on that path. Smilie
# 5  
Old 09-06-2013
Hello,
You can do it like:
Code:
wc -l < <(ls -1 | tee /dev/tty && echo -n "Total: " >/dev/tty)

But, i think awk solution will better.

Regards.
# 6  
Old 09-06-2013
Assuming that you want the names of files in the current directory (including those whose first character is a dot (.)) and that no file in the current directory have names that contain a newline character:
Code:
ls -f | wc -l

will give you the number of files in the current directory.

If you want a sorted list of the files in the current directory followed by the number of files, try:
Code:
ls -a | tee /dev/tty | wc -l

# 7  
Old 09-06-2013
This does work.

print "Total: \c" && (ls -lrt | grep "\." | wc -l)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Counting total files with different file types in each folder

Trying to count total files with different file types with thousands of files in each folder. Since some files do not have extensions I have to use below criteria. Count Total Files starting with --> "^ERROR" Count Total Files starting with --> "^Runtime" Count Everything else or files... (3 Replies)
Discussion started by: kchinnam
3 Replies

2. Shell Programming and Scripting

Performance of calculating total number of matching records in multiple files

Hello Friends, I've been trying to calculate total number of a certain match in multiple data records files (DRs). Let say I have a daily created folders for each day since the beginning of july like the following drwxrwxrwx 2 mmsuper med 65536 Jul 1 23:59 20150701 drwxrwxrwx 2 mmsuper... (1 Reply)
Discussion started by: EAGL€
1 Replies

3. HP-UX

Total number of files in a FS

Hello people, On HP-UX B.11.11 U 9000/800 How can I have in aprox. the total number of files in a specific FS? Is the number of used inodes a rough estimation of my total number of files? Server1 /Data:df -i . /Data (/dev/vg_Data/lvol1 ) : 18292960 total i-nodes 15800945 free... (3 Replies)
Discussion started by: drbiloukos
3 Replies

4. UNIX for Dummies Questions & Answers

[Solved] Touch 10% of the total files inside a folder

I'm trying to make this code below to work but I can't find the way to do the following: I want to make the script to touch only 10% of the total amount of files counted inside the given directory instead of all like it is now. I would greatly appreciate it if someone can give me a direction on... (9 Replies)
Discussion started by: regraphix
9 Replies

5. UNIX for Dummies Questions & Answers

Write the total number of rows in multiple files into another file

Hello Friends, I know you all are busy and inteligent too... I am stuck with one small issue if you can help me then it will be really great. My problem is I am having some files i.e. Input.txt1 Input.txt2 Input.txt3 Now my task is I need to check the total number of rows in... (4 Replies)
Discussion started by: malaya kumar
4 Replies

6. UNIX for Dummies Questions & Answers

Command for total number of files (and size) across subdirectories?

Hi all... I have a directory called dbrn. This directory contains an unknown number of subdirectories which in turn contain an unknown number of files. What I want to know is: How many files with extention .ABC can be found in /dbrn across all subdirecties, and what is the total size for... (9 Replies)
Discussion started by: Beun
9 Replies

7. Shell Programming and Scripting

perl script on how to count the total number of lines of all the files under a directory

how to count the total number of lines of all the files under a directory using perl script.. I mean if I have 10 files under a directory then I want to count the total number of lines of all the 10 files contain. Please help me in writing a perl script on this. (5 Replies)
Discussion started by: adityam
5 Replies

8. Shell Programming and Scripting

check how many files in folder or total files in folder

Hi all, I have copied all my files to one folder.and i want to check how many files (count) in the folder recently moved or total files in my folder? please send me the query asap. (3 Replies)
Discussion started by: durgaprasad
3 Replies

9. UNIX for Dummies Questions & Answers

total number of files which have "aaa" in files whose names are File*_bbb*

I am getting the list of all the files which have "aaa" from files whose name is File*_bbb*. grep -l "aaa" File*_bbb* But I want to count the number of files. That is I want the total number of files which have "aaa" in files File*_bbb* If I run the following for getting number of... (1 Reply)
Discussion started by: sudheshnaiyer
1 Replies

10. HP-UX

CVSWeb - Directories listed but files not listed

I am using CVSWeb on HPUnix. When i access it, all directories are listed but files are not listed. I am getting the error "NOTE: There are 51 files, but none matches the current tag. " in tomcat sevrer log i am getting the message "rlog warning: Missing revision or branch number after -r"... (0 Replies)
Discussion started by: ganesh
0 Replies
Login or Register to Ask a Question