输出ls -l size字段,其数字按千位分组?


13

可以使ls -l输出具有以千位分组的数字的size字段吗?如果是这样,怎么办?

例如:

$ ls -l
-rw-rw---- 1 dahl dahl 43,210,052 2012-01-01 21:52 test.py

(请注意逗号的大小)。

也许是通过修改我正在使用的语言环境(en_US.utf8)中的LC_NUMERIC设置?

我正在使用Kubuntu 12.04 LTS。


test.py有多大?您要字节,千字节,兆字节...吗?
Mikel,2012年

Answers:


20

块大小-GNU Coreutils

前面带有'的块大小规格会导致输出大小以数千个分隔符显示。(请注意,仅指定块大小是不够的)。

因此,根据您的需求,您可以尝试

BLOCK_SIZE="'1" ls -l
BLOCK_SIZE="'1kB" ls -l

要么

ls -l --block-size="'1"
ls -l --block-size="'1kB"

您可以使用永久性

export BLOCK_SIZE="'1"
export BLOCK_SIZE="'1kB"

要么

alias ls="ls --block-size=\"'1\""
alias ls="ls --block-size=\"'1kB\""

我在Macos Sierra上获得以下输出:ls: illegal option -- - usage: ls [-ABCFGHLOPRSTUWabcdefghiklmnopqrstuwx1] [file ...]
Matthew

Matt,这个问题最初是关于Kubuntu Linux的。FreeBSD有,-,但我在Mac OS上看不到。
Mikel

注意:通常需要设置LC_NUMERIC=en_US等值LC_NUMERIC=en_US ls -l --block-size="'1"
Al Bundy

0

随着AST开的ls(也是ls的内置ksh93如果建成AST开的部分):

$ ls -rSZ "%(mode)s %3(nlink)u %-8(uid)s %-8(gid)s %8(device:case::%'(size)u:*:%(device)s)s %(mtime)s %(name)s%(linkop:case:?*: %(linkop)s %(linkpath)s)s"
[...]
-rwxrwxr-x   1 chazelas chazelas 2,701,278 Apr 27  2016 nmake
-rwxrwxr-x   2 chazelas chazelas 4,515,954 Apr 27  2016 ksh
-rwxrwxr-x   2 chazelas chazelas 4,515,954 Apr 27  2016 bash
-rwxrwxr-x   1 chazelas chazelas 4,542,177 Apr 27  2016 shcomp
-rwxrwxr-x   1 chazelas chazelas 6,830,418 Apr 27  2016 tksh

这是通常使用的格式,ls -l但已%(size)u更改%'(size)u为显示千位分隔符。

更清晰:

LONG_FORMAT_WITH_THOUSAND_SEP="\
%(mode)s \
%3(nlink)u \
%-8(uid)s \
%-8(gid)s \
%8(device:case::%'(size)u:*:%(device)s)s \
%(mtime)s \
%(name)s\
%(linkop:case:?*: %(linkop)s %(linkpath)s)s"

ls -rSZ "$LONG_FORMAT_WITH_THOUSAND_SEP"

-3

从手册页

--block-size=SIZE
          scale sizes by SIZE before printing them.  E.g., `--block-size=M'   
          prints sizes in units of 1,048,576 bytes.  See SIZE format below.

_这是ls的手册页,请记住man是您最好的朋友,在终端中键入“ man man”以了解它的用处。

    ls

List information about files.

Syntax
      ls [Options]... [File]...

Key
      Sort entries alphabetically if none of -cftuSUX nor --sort.

  -a, --all                  Do not hide entries starting with .

  -A, --almost-all           Do not list implied . and ..

  -b, --escape               Print octal escapes for nongraphic characters

      --block-size=SIZE      Use SIZE-byte blocks

  -B, --ignore-backups       Do not list implied entries ending with ~

  -c                         Sort by change time; with -l: show ctime

  -C                         List entries by columns

      --color[=WHEN]         Control whether color is used to distinguish file
                             types. WHEN may be `never', `always', or `auto'

  -d, --directory            List directory entries instead of contents

  -D, --dired                Generate output designed for Emacs' dired mode

  -f                         Do not sort, enable -aU, disable -lst

  -F, --classify             Append indicator (one of */=@|) to entries

      --format=WORD          Across -x, commas -m, horizontal -x, long -l,
                             single-column -1, verbose -l, vertical -C

      --full-time            List both full date and full time

  -g                         (ignored)

  -G, --no-group             Inhibit display of group information

  -h, --human-readable       Print sizes in human readable format (e.g., 1K 234M 2G)
  -H, --si                   Likewise, but use powers of 1000 not 1024

      --indicator-style=WORD Append indicator with style WORD to entry names:
                             none (default), classify (-F), file-type (-p)

  -i, --inode                Print index number of each file

  -I, --ignore=PATTERN       Do not list implied entries matching shell PATTERN

  -k, --kilobytes            Like --block-size=1024

  -l                         Use a long listing format

  -L, --dereference          List entries pointed to by symbolic links

  -m                         Fill width with a comma separated list of entries

  -n, --numeric-uid-gid      List numeric UIDs and GIDs instead of names

  -N, --literal              Print raw entry names (don't treat e.g. control
                             characters specially)

  -o                         Use long listing format without group info

  -p, --file-type            Append indicator (one of /=@|) to entries

  -q, --hide-control-chars   Print ? instead of non graphic characters

      --show-control-chars   Show non graphic characters as-is (default)

  -Q, --quote-name           Enclose entry names in double quotes
      --quoting-style=WORD   Use quoting style WORD for entry names:
                             literal, shell, shell-always, c, escape

  -r, --reverse              Reverse order while sorting

  -R, --recursive            List subdirectories recursively

  -s, --size                 Print size of each file, in blocks

  -S                         Sort by file size

      --sort=WORD            time -t, version -v, status -c 
                             size -S, extension -X, none -U
                             atime -u, access -u, use -u

      --time=WORD            Show time as WORD instead of modification time:
                               atime, access, use, ctime or status; 
                               also use this as a sort key if --sort=time

  -t                         sort by modification time

  -T, --tabsize=COLS         assume tab stops at each COLS instead of 8

  -u                         sort by last access time; with -l: show atime

  -U                         do not sort; list entries in directory order

  -v                         sort by version

  -w, --width=COLS           assume screen width instead of current value

  -x                         list entries by lines instead of by columns

  -X                         sort alphabetically by entry extension

  -1                         list one file per line

      --help                 display help and exit

      --version              output version information and exit
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.