Solved

Search for largest file type size

Posted on 2003-12-03
6
3,190 Views
Last Modified: 2010-04-21
I need the command to get the file size (MB) of the largest file type of ".pdf" starting in a directory and  searching any sub-dirs also!
0
Comment
Question by:894359
6 Comments
 
LVL 62

Expert Comment

by:gheist
ID: 9870938
find . -iname "*.pdf" -ls | sort +6 | tail -1
---Explanation:
find - command
. - directory you want to start with
-iname - use name mask
"*.pdf" - what you asked for
-ls - show file list from find
| - shell pipe
sort  - a command
+6 - use 6th column of output
| - shell pipe
tail - get some lines of a file
-1 - last line
---Problems possible:
column 6 is not posix, nor I am sure find is 100% posix-accurate, you may need to adjust to your environment.
Tested and worked  only on FreeBSD 5.1 in five minutes.
Slow will be because find loads namei function of filesystem, sort uses some memory , tail waits for both, add time command before each command to read what happens.

0
 
LVL 38

Assisted Solution

by:yuzh
yuzh earned 250 total points
ID: 9872323
find . -type f -name "*.pdf" -ls | sort +6 | tail -1

or

find / -type f -name "*.pdf" -ls | sort +6 | tail -1

To get the filename and size of the file, than convert the size to MB use:

SIZEofFILE/1024






0
 
LVL 62

Expert Comment

by:gheist
ID: 9872740
-type f  important for sure
size/(1024*1024) or size/(1000*1000) depending on 894359's definition of megabyte
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
LVL 7

Accepted Solution

by:
glassd earned 250 total points
ID: 9872745
Some versions of find do not include the '-ls' option, so:

find . -type f -name "*.pdf" -exec ls -l {} \; | sort +6 | tail -1
0
 
LVL 62

Expert Comment

by:gheist
ID: 9872784
and there is file command which analyzes file content
find . -type f -exec file \{\} \; | awk -F: "/PDF/{print $1}" | xargs ls -l | sort +XX | tail -1
0
 

Author Comment

by:894359
ID: 9875974
I will be try these Friday! Thanks!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question