ls顯示檔案大小時顯示單位

來源:互聯網
上載者:User

在linux中顯示檔案大小的時候,通常的做法是使用“ls -l”,顯示的大小是檔案的位元組大小。
但是,如果檔案比較大的話,顯示起來不是特別易讀,這個時候,可以使用“ls -lh”,就可以使用比較接近檔案大小的單位顯示檔案的大小,如下:

[billing_dx@bmcs1 bin]$ ls -lhtotal 565M-rwxr-xr-x 1 billing_dx BILLING 1.1M Mar 10 18:56 AcctMgrService-rw-r--r-- 1 billing_dx BILLING  364 Mar 10 18:59 AcctMgrService.conf-rw------- 1 billing_dx BILLING  11G Mar 13 18:37 core.22836-rw-r--r-- 1 billing_dx BILLING  410 Mar 13 17:38 dll_info.conf-rwxr-xr-x 1 billing_dx BILLING   39 Mar 10 18:57 go



使用“-h”參數時,會根據檔案的大小選擇顯示的單位是“K”、“M”還是“G”。如果希望指定顯示的單位,可以使用“--block-size”參數,如下:

[billing_dx@bmcs1 bin]$ ls -ltotal 577724-rwxr-xr-x 1 billing_dx BILLING     1103862 Mar 10 18:56 AcctMgrService-rw-r--r-- 1 billing_dx BILLING         364 Mar 10 18:59 AcctMgrService.conf-rw------- 1 billing_dx BILLING 10947788800 Mar 13 18:37 core.22836-rw-r--r-- 1 billing_dx BILLING         410 Mar 13 17:38 dll_info.conf-rwxr-xr-x 1 billing_dx BILLING          39 Mar 10 18:57 go[billing_dx@bmcs1 bin]$ ls -l --block-size=k total 577724K-rwxr-xr-x 1 billing_dx BILLING     1078K Mar 10 18:56 AcctMgrService-rw-r--r-- 1 billing_dx BILLING        1K Mar 10 18:59 AcctMgrService.conf-rw------- 1 billing_dx BILLING 10691200K Mar 13 18:37 core.22836-rw-r--r-- 1 billing_dx BILLING        1K Mar 13 17:38 dll_info.conf-rwxr-xr-x 1 billing_dx BILLING        1K Mar 10 18:57 go[billing_dx@bmcs1 bin]$ ls -l --block-size=mtotal 565M-rwxr-xr-x 1 billing_dx BILLING     2M Mar 10 18:56 AcctMgrService-rw-r--r-- 1 billing_dx BILLING     1M Mar 10 18:59 AcctMgrService.conf-rw------- 1 billing_dx BILLING 10441M Mar 13 18:37 core.22836-rw-r--r-- 1 billing_dx BILLING     1M Mar 13 17:38 dll_info.conf-rwxr-xr-x 1 billing_dx BILLING     1M Mar 10 18:57 go[billing_dx@bmcs1 bin]$ ls -l --block-size=gtotal 1G-rwxr-xr-x 1 billing_dx BILLING  1G Mar 10 18:56 AcctMgrService-rw-r--r-- 1 billing_dx BILLING  1G Mar 10 18:59 AcctMgrService.conf-rw------- 1 billing_dx BILLING 11G Mar 13 18:37 core.22836-rw-r--r-- 1 billing_dx BILLING  1G Mar 13 17:38 dll_info.conf-rwxr-xr-x 1 billing_dx BILLING  1G Mar 10 18:57 go



同哦過對比可以看到,使用  不同的單位顯示的時候,使用的是進一法,所以一個1k的東西,使用G為單位顯示的是,會顯示為“1G”。所以,還是使用“-h”顯示起來,更符合人的習慣。
下面是ls顯示的相關描述:
billing_dx@bmcs1 bin]$ man lsLS(1)                            User Commands                           LS(1)NAME   ls - list directory contentsSYNOPSIS   ls [OPTION]... [FILE]...DESCRIPTION   List  information  about the FILEs (the current directory by default).  Sort entries alphabetically if   none of -cftuvSUX nor --sort.   Mandatory arguments to long options are mandatory for short options too.   -h, --human-readable          with -l, print sizes in human readable format (e.g., 1K 234M 2G)   -k     like --block-size=1K   -l     use a long listing format   --block-size=SIZE          use SIZE-byte blocks.  See SIZE format below   SIZE  may  be  (or  may  be  an  integer optionally followed by) one of following: KB 1000, K 1024, MB   1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.


          
擴充閱讀: http://hi.baidu.com/shiliangshuai/item/2310fac2ce7aa3bb0c0a7b3f 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.