Count files in every subdirectory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count files in every subdirectory
# 1  
Old 08-12-2008
Count files in every subdirectory

Hi

if anyone could help me Smilie
I did a lot of search and 70% of answer is "how to count files in all subdirectories".

A basic problem for me is how to count files in every subdirectory separately then sort it by number of files

For example:
dir1
file1
file2
subdir11
dir2
dir3
file4

desired result from script:
dir2 0
dir3 1
dir1 2

More detailed problem: count only soflinks referring to certain extension in one subdir level only.

For example:
dir1
link1 to jpg file somewhere
link2 to txt file somewhere
txt file
subdir11
dir2
link2 to jpg file somewhere
link3 to jpg file somewhere

Say I am interested in link to jpgs only. Then sort it by number of occurences

Desired result:
dir1 1
dir2 2

Any help welcome. Bash, perl, python whatever. As simple as possible, please.

Yorr
# 2  
Old 08-12-2008
What do you consider a file?
In the Unix sense, almost anything, except maybe other dirs?
# 3  
Old 08-12-2008
Also, does the file name's extension reflects its type, or will we need to pass each file to e.g. file(1) to find out what's inside?

Code:
vnix$ file random
random: symbolic link to `ick/y/poo'
vnix$ file ick/y/poo
ick/y/poo: JPEG image data, JFIF standard 1.01

# 4  
Old 08-12-2008
some clarification

Quote:
Originally Posted by buffoonix
What do you consider a file?
In the Unix sense, almost anything, except maybe other dirs?
Thanks for interest in my problem.
Whatever a file really is - I am interested in softlinks only.
Softlinks have the same name and extention as file they are pointing to.

Some background. What is it for.
I do a lot of photos /jpg / of my city. They sit in directiories organized by day.
Then I have directory 'city_by_street'. Exactly 5500 street_name directories.
Each street_name is a directory. Into these directories falls softlinks.jpg pointing to actual files. Some street_name directories have subdirectiores that I would like to ignore in my problem /eg. Best, Logo, whatever/
Finally - I would like to know which street_name directory have the smallest number of photos /in this case softlinks with jpg extension/ - so I could update it first.
Again, example:
Aba_Street /there are no whitespaces, no strange characters etc/
Best /subdirectory to ignore with whatever content inside/
Winter /subdirectory to ignore/
20080202_001.jpg /softlink/
Ada_Street
20080103_003.jpg /softlink/
20080422_001.jpg /softlink/

Desired output of the script:
Aba_Street 1
Ada_Street 2

Then I know I need to go to Aba Street first.

Thanks again

Yorr
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Error files count while coping files from source to destination locaton as well count success full

hi All, Any one answer my requirement. I have source location src_dir="/home/oracle/arun/IRMS-CM" My Target location dest_dir="/home/oracle/arun/LiveLink/IRMS-CM/$dc/$pc/$ct" my source text files check with below example.text file content $fn "\t" $dc "\t" $pc "\t" ... (3 Replies)
Discussion started by: sravanreddy
3 Replies

2. UNIX for Dummies Questions & Answers

Copy non-empty files into subdirectory

How to Copy non-empty files into subdirectory I have directory A there are bunch of files: a.txt a.txt.target b.txt b.target.txt....... How can i find out the non-empty file within *.txt.target and copy them into a subdirectory B? Thank you. (2 Replies)
Discussion started by: grace_shen
2 Replies

3. Shell Programming and Scripting

how to count how many subdirectory containing more than a certain number of specific file type

hi I want to write a script which count the number of subdirectories in the current root directory that contain more than a specified number of files of a specific type. Is there an easy way to do this? Thanks Robert (2 Replies)
Discussion started by: piynik
2 Replies

4. UNIX for Dummies Questions & Answers

How to Find files in subdirectory?

I am trying to find all DAT files in a subdirectory named IN. I do not know the entire path. For example: /stage/<?>/<?>/IN/file.DAT I am using the find command without success: find /stage -name IN -a -name '*.DAT' -print What is the correct logic and syntax? Thank you for the help. (5 Replies)
Discussion started by: TwinGT
5 Replies

5. UNIX for Dummies Questions & Answers

Listing files in subdirectory

Forgive me if there is an answer to this somewhere in the forums. I've gone through as much as I could but couldn't find a relevant answer. What I'm trying to do is use the ll command to list some files in a subdirectory that matches a certain format. I've tried ll *.*a* <subdirectory> but... (3 Replies)
Discussion started by: archaic
3 Replies

6. UNIX for Dummies Questions & Answers

How to move all files in a directory and subdirectory?

I'm trying to organize my MB Pro by moving all my jpeg files to a single folder from the desktop. There are some on the desktop that are not in any folder. I was at the command line and typed mv *.jpg "Jpeg files" but it only moved the files that were on the desktop, not any of the ones that... (3 Replies)
Discussion started by: Straitsfan
3 Replies

7. Shell Programming and Scripting

search text in files within the subdirectory

Hello, I am trying to write a shell script to search for a pattern in the directory and show only one entry for each field, essentially I am looking to search for a pattern in a file and list that file name. (1 Reply)
Discussion started by: grajp002
1 Replies

8. Solaris

How Prevent from deleting subdirectory files

Hi All, I am using the foolowing find /home/vcrd/put -name '*.z' -mtime +5 -exec rm -f {} \; in a shell script, it is deleting all file having *.z in /home/vcrd/put/appl sub directory. I donot want the files in the subdirectory are deleted. Regards Megh (2 Replies)
Discussion started by: megh
2 Replies

9. Shell Programming and Scripting

How to deleting some files under subdirectory

Hi guys, sorry if my english not very well.. i have a problem.. i have a file and the structure is : Folder/ Folder/10.123.124.20/pm_data/A200807 Folder/10.123.124.20/pm_data/A200807 Folder/10.123.124.20/pm_data/A200807 Folder/10.123.124.20/pm_data/A200808... (4 Replies)
Discussion started by: AdziE
4 Replies

10. UNIX for Dummies Questions & Answers

How can I copy files and subdirectory?

I am trying to copy some files from one location to another and I need to write a script to move all the files and the subdirectories to the new location (both unix), but excluding the temp directory. i.e., I want to avoid copying my temp subdirectories during the process of copying other files... (3 Replies)
Discussion started by: odogbolu98
3 Replies
Login or Register to Ask a Question