How do I get the find command to print out the file size with the file name?

前端 未结 15 549
无人及你
无人及你 2020-12-07 11:01

If I issue the find command as follows:

$ find . -name *.ear

It prints out:

./dir1/dir2/earFile1.ear
./dir1/dir2/earFile2.         


        
相关标签:
15条回答
  • 2020-12-07 11:49
    find . -name "*.ear" -exec ls -l {} \;
    
    0 讨论(0)
  • 2020-12-07 11:52

    a simple solution is to use the -ls option in find:

    find . -name \*.ear -ls
    

    That gives you each entry in the normal "ls -l" format. Or, to get the specific output you seem to be looking for, this:

    find . -name \*.ear -printf "%p\t%k KB\n"
    

    Which will give you the filename followed by the size in KB.

    0 讨论(0)
  • 2020-12-07 11:53

    You need to use -exec or -printf. Printf works like this:

    find . -name *.ear -printf "%p %k KB\n"
    

    -exec is more powerful and lets you execute arbitrary commands - so you could use a version of 'ls' or 'wc' to print out the filename along with other information. 'man find' will show you the available arguments to printf, which can do a lot more than just filesize.

    [edit] -printf is not in the official POSIX standard, so check if it is supported on your version. However, most modern systems will use GNU find or a similarly extended version, so there is a good chance it will be implemented.

    0 讨论(0)
提交回复
热议问题