Solved

Search for largest file type size

Posted on 2003-12-03
6
3,204 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 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
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!

 
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

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

I have been running these systems for a few years now and I am just very happy with them.   I just wanted to share the manual that I have created for upgrades and other things.  Oooh yes! FreeBSD makes me happy (as a server), no maintenance and I al…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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.

740 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