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

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

    Awk can fix up the output to give just what the questioner asked for. On my Solaris 10 system, find -ls prints size in KB as the second field, so:

    % find . -name '*.ear' -ls | awk '{print $2, $11}'
    5400 ./dir1/dir2/earFile2.ear
    5400 ./dir1/dir2/earFile3.ear
    5400 ./dir1/dir2/earFile1.ear
    

    Otherwise, use -exec ls -lh and pick out the size field from the output. Again on Solaris 10:

    % find . -name '*.ear' -exec ls -lh {} \; | awk '{print $5, $9}'
    5.3M ./dir1/dir2/earFile2.ear
    5.3M ./dir1/dir2/earFile3.ear
    5.3M ./dir1/dir2/earFile1.ear
    

提交回复
热议问题