Solved

Search for largest file type size

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

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 61

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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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 61

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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 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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now