December 19, 2010

How to find files larger than X

You can use the following command to find files that are larger than 50M.

mike@shiner $ find . -type f -size +50000k

The -type argument tells find that we want to look at files and the -size argument specifies files larger than 50,000k. We can use the following command to get a nicely formatted output with the name of the file and the size.

mike@shiner $ find . -type f -size +50000k -exec ls -lh {} \; | awk '{ print $9 ": " $5 }' 

Alternatively, we can do the following to get the same output.

mike@shiner $ find . -type f -size +50000k | xargs ls -lh | awk '{ print $9 ": " $5 }' 

xargs is a handy command that takes each line of input and passes it to the proceeding command, which in this case is ls -lh.

2 comments:

  1. xargs and awk in this examples are not working if files contains white space in the name (e.g. "My Image.jpg").

    ReplyDelete
  2. This characteristic is Bike Helmets of limited use to most individuals, and the precise print companies are dealt with through partnerships with labs like Bay Photo, EZprints, and WHCC, corporations have the ability to|you probably can} order directly from instead. Apparently the corporate was sold to new ownership recently, and during the transition many customers lost entry to their photographs hosted on the company’s servers. That, coupled with the fact that|the fact that} the only buyer support out there is through a Web form—there’s no telephone number or even an e-mail option—made Winkflash a straightforward dismissal.

    ReplyDelete