Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Search for largest file type size

Posted on 2003-12-03
6
Medium Priority
?
3,219 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1000 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Accepted Solution

by:
glassd earned 1000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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 …
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…
Suggested Courses

636 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