Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find files of specified size using bash in Unix [closed]

Tags:

bash

unix

I am looking for a Unix command to print the files with its size. I used this but it didn't work.

find . -size +10000k -print. 

I want to print the size of the file along with the filename/directory.

like image 220
Kannan Lg Avatar asked Apr 09 '12 20:04

Kannan Lg


People also ask

How do I find the size of a specific file in Unix?

don't worry we have a got a UNIX command to do that for you and command is "df" which displays the size of the file system in UNIX. You can run "df" UNIX command with the current directory or any specified directory.

How do I see file size in bash?

Another method we can use to grab the size of a file in a bash script is the wc command. The wc command returns the number of words, size, and the size of a file in bytes.


2 Answers

find . -size +10000k -exec ls -sd {} + 

If your version of find won't accept the + notation (which acts rather like xargs does), then you might use (GNU find and xargs, so find probably supports + anyway):

find . -size +10000k -print0 | xargs -0 ls -sd 

or you might replace the + with \; (and live with the relative inefficiency of this), or you might live with problems caused by spaces in names and use the portable:

find . -size +10000k -print | xargs ls -sd 

The -d on the ls commands ensures that if a directory is ever found (unlikely, but...), then the directory information will be printed, not the files in the directory. And, if you're looking for files more than 1 MB (as a now-deleted comment suggested), you need to adjust the +10000k to 1000k or maybe +1024k, or +2048 (for 512-byte blocks, the default unit for -size). This will list the size and then the file name. You could avoid the need for -d by adding -type f to the find command, of course.

like image 71
Jonathan Leffler Avatar answered Oct 01 '22 12:10

Jonathan Leffler


Find can be used to print out the file-size in bytes with %s as a printf. %h/%f prints the directory prefix and filename respectively. \n forces a newline.

Example

find . -size +10000k -printf "%h/%f,%s\n" 

Output

./DOTT/extract/DOTT/TENTACLE.001,11358470 ./DOTT/Day Of The Tentacle.nrg,297308316 ./DOTT/foo.iso,297001116 
like image 29
Adam Avatar answered Oct 01 '22 10:10

Adam