Solved

Search for largest file type size

Posted on 2003-12-03
6
3,195 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

828 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