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.
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.
Assuming you have GNU find:
If you want a constant width for the size field, you can do something like:
Note that
-size +1000k
selects files of at least 10,240,000 bytes (k
is 1024, not 1000). You said in a comment that you want files bigger than 1M; if that's 1024*1024 bytes, then this:will do the trick -- except that it will also print the size and name of files that are exactly 1024*1024 bytes. If that matters, you could use:
You need to decide just what criterion you want.
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
Output
If your version of
find
won't accept the+
notation (which acts rather likexargs
does), then you might use (GNUfind
andxargs
, sofind
probably supports+
anyway):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:The
-d
on thels
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
to1000k
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 thefind
command, of course.