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

前端 未结 15 570
无人及你
无人及你 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: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.

提交回复
热议问题