茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1697626 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
PIMG_00107.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

小企鵝開談 : [自創]如何讓檔案排序顯示

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[自創]如何讓檔案排序顯示
當然我們還是用 ls 來列出檔案,
所以我們先來看看 ls 的基本說明:
LinuxS:~> ls --help
Usage: /bin/ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
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            extension -X, none -U, size -S, time -t,
                               version -v
                             status -c, time -t, atime -u, access -u, use -u
      --time=WORD            show time as WORD instead of modification time:
                               atime, access, use, ctime or status; use
                               specified time as 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 this help and exit
      --version              output version information and exit

By default, color is not used to distinguish types of files.  That is
equivalent to using --color=none.  Using the --color option without the
optional WHEN argument is equivalent to using --color=always.  With
--color=auto, color codes are output only if standard output is connected
to a terminal (tty).

Report bugs to <bug-fileutils@gnu.org>.

ls 的用法:
ls -c 可公讓檔名順序排序 (由a到z)
ls -r 可以讓檔名反向排序 (由z到a)
ls -t 可以依照檔案修改時間排序 (由新到舊)
ls --sort=XXX 讓檔名以你指定的方式排序,XXX可以為:
extension -- 以副檔名為排序依據( 也就是 ls -X ),
none ( 也就是 ls -U ),
size -- 以檔案大小為排序依據 ( 也就是 ls -S ),
time -- 以檔案存取時間為排序依據 ( 也就是 ls -t ),
version -- 以版本為排序依據 ( 也就是 ls -v)

想要查看更多的用法嗎 ? 在 Linux 的命令列下: man ls 的指令就能看到喔:
LinuxS:~> man ls
NAME
       ls, dir, vdir - list directory contents

SYNOPSIS
       ls [options] [file...]

       POSIX options: [-CFRacdilqrtu1]

       GNU  options  (shortest form): [-1abcdfgiklmnopqrstuxABCD-
       FGLNQRSUX] [-w cols] [-T cols] [-I pattern]  [--full-time]
       [--format={long,verbose,commas,across,vertical,single-col-
       umn}]                  [--sort={none,time,size,extension}]
       [--time={atime,access,use,ctime,status}]
       [--color[={none,auto,always}]] [--help] [--version] [--]

DESCRIPTION
       The program ls lists first its  non-directory  file  argu-
       ments,  and  then for each directory argument all listable
       files contained within that directory.  If  no  non-option
       arguments are present, a default argument `.' (the current
       directory) is assumed.  The -d option  causes  directories
       to  be  treated  as  non-directory  arguments.   A file is
       listable when either its name does not start with `.',  or
       the -a option is given.

       Each  of  the lists of files (that of non-directory files,
       and for each directory the list of files inside) is sorted
       separately according to the collating sequence in the cur-
       rent locale.  When the -l option is given,  each  list  is
       preceded  by  a  summary line giving the total size of all
       files in the list, measured in semi-kilobytes (512 B).

       The output is to stdout, one entry per line, unless multi-
       column  output is requested by the -C option. However, for
       output to a terminal, it is undefined whether  the  output
       will  be single-column or multi-column. The options -1 and
       -C can be used to  force  single-column  and  multi-column
       output, respectively.

POSIX OPTIONS
       -C     List files in columns, sorted vertically.

       -F     Suffix each directory name with `/', each FIFO name
              with `|', and each name of an executable with  `*'.

       -R     Recursively list subdirectories encountered.

       -a     Include  files with a name starting with `.' in the
              listing.

       -c     Use the status change time instead of the modifica-
              tion  time  for  sorting (with -t) or listing (with
              -l).
       -d     List names of directories like other files,  rather
              than listing their contents.

       -i     Precede  the output for the file by the file serial
              number (i-node number).

       -l     Write (in single-column format) the file mode,  the
              number  of  links  to the file, the owner name, the
              group name, the size of the file  (in  bytes),  the
              timestamp,  and  the  filename.   By  default,  the
              timestamp shown is that of the  last  modification;
              the  options  -c and -u select the other two times-
              tamps.  For device special files the size field  is
              commonly  replaced  by  the  major and minor device
              numbers.

       -q     Output nonprintable characters  in  a  filename  as
              question  marks.   (This  is  permitted  to  be the
              default for output to a terminal.)

       -r     Reverse the order of the sort.

       -t     Sort by the timestamp shown.

       -u     Use the time of last access instead of the  modifi-
              cation  time for sorting (with -t) or listing (with
              -l).

       -1     For single-column output.

GNU DETAILS
       If standard output is a terminal, the output is in columns
       (sorted vertically).
       dir  (also  installed as d) is equivalent to `ls -C'; that
       is, files are by default listed in columns, sorted  verti-
       cally.   vdir  (also  installed as v) is equivalent to `ls
       -l'; that is, files are by default listed in long  format.

GNU OPTIONS
       -1, --format=single-column
              List  one  file  per  line. This is the default for
              when standard output is not a terminal.

       -a, --all
              List all files in directories, including all  files
              that start with `.'.

       -b, --escape
              Quote  nongraphic  characters  in  file names using
              alphabetic and octal backslash sequences like those
              used in C.
       -c, --time=ctime, --time=status
              Sort  directory  contents  according  to the files'
              status change time (the `ctime' in the  inode).  If
              the  long  listing  format is being used (-l) print
              the status change time instead of the  modification
              time.

       -d, --directory
              List  names of directories like other files, rather
              than listing their contents.

       -f     Do not sort directory contents; list them in  what-
              ever  order  they  are  stored  on  the disk.  Also
              enables -a and disables -l, --color, and -s if they
              were specified before the -f.

       -g     Ignored; for Unix compatibility.

       -i, --inode
              Print the inode number (also called the file serial
              number and index number) of each file to  the  left
              of  the file name. (This number uniquely identifies
              each file within a particular filesystem)

       -k, --kilobytes
              If file sizes are being listed, print them in kilo-
              bytes.

       -l, --format=long, --format=verbose
              In  addition  to  the  name of each file, print the
              file type, permissions, number of hard links, owner
              name, group name, size in bytes, and timestamp (the
              modification time unless other times are selected).
              For  files  with  a time that is more than 6 months
              old or more than 1 hour into the future, the times-
              tamp  contains the year instead of the time of day.

              For each directory  that  is  listed,  preface  the
              files  with  a line `total blocks', where blocks is
              the total disk space used  by  all  files  in  that
              directory.   By default, 1024-byte blocks are used;
              if the environment variable POSIXLY_CORRECT is set,
              512-byte  blocks  are used (unless the -k option is
              given). The blocks computed counts each  hard  link
              separately; this is arguably a deficiency.

              The permissions listed are similar to symbolic mode
              specifications but ls combines multiple  bits  into
              the third character of each set of permissions

              s      If  the  setuid or setgid bit and the corre-
                     sponding executable bit are both set.

              S      If the setuid or setgid bit is set  but  the
                     corresponding executable bit is not set.

              t      If  the  sticky bit and the other-executable
                     bit are both set.

              T      If the sticky bit is set but the  other-exe-
                     cutable bit is not set.

              x      If the executable bit is set and none of the
                     above apply.

              -      Otherwise.

       -m, --format=commas
              List files horizontally, with as many as  will  fit
              on  each  line,  each  separated  by  a comma and a
              space.

       -n, --numeric-uid-gid
              List the numeric UID and GID instead of the  names.

       -o     Produce  long  format directory listings, but don't
              display group information.   It  is  equivalent  to
              using  --format=long  --no-group.   This  option is
              provided for compatibility with other  versions  of
              ls.

       -p     Append a character to each file name indicating the
              file type. This is like -F except that  executables
              aren't marked.

       -q, --hide-control-chars
              Print  question marks instead of nongraphic charac-
              ters in file names. This is the default.

       -r, --reverse
              Sort directory contents in reverse order.

       -s, --size
              Print the size of each file in 1024-byte blocks  to
              the  left  of  the  file  name.  If the environment
              variable POSIXLY_CORRECT is  set,  512-byte  blocks
              are used instead, unless the -k option is given.

       -t, --sort=time
              Sort  by  modification  time  (the  `mtime'  in the
              inode) instead of alphabetically, with  the  newest
              files listed first.

       -u, --time=atime, --time=access, --time=use
              Sort  directory  contents  according  to the files'
              last access time instead of the  modification  time
              (the  `atime'  in  the  inode). If the long listing
              format is being used, print the  last  access  time
              instead of the modification time.

       -w, --width cols
              Assume  the  screen  is  cols  columns  wide.   The
              default is taken from the terminal driver if possi-
              ble;  otherwise the environment variable COLUMNS is
              used if it is set; otherwise the default is 80.

       -x, --format=across, --format=horizontal
              List the files in columns, sorted horizontally.

       -A, --almost-all
              List all files in directories, except for  `.'  and
              `..'.

       -B, --ignore-backups
              Do  not  list  files that end with `~', unless they
              are given on the command line.

       -C, --format=vertical
              List files in columns, sorted vertically.  This  is
              the default if standard output is a terminal. It is
              always the default for dir and d.

       -D, --dired
              With the long listing (-l) format, print  an  addi-
              tional line after the main output:
              //DIRED// BEG1 END1 BEG2 END2 ...

              The  BEGn  and  ENDn  are  unsigned  integers which
              record the byte position of the beginning  and  end
              of each file name in the output. This makes it easy
              for Emacs to find the names, even when they contain
              unusual  characters such as space or newline, with-
              out fancy searching.

              If directories are being listed  recursively  (-R),
              output a similar line after each subdirectory:
              //SUBDIRED// BEG1 END1 ...

       -F, --classify, --file-type
              Append a character to each file name indicating the
              file type.  For regular files that are  executable,
              append a `*'.  The file type indicators are `/' for
              directories, `@' for symbolic links, `|' for FIFOs,
              `=' for sockets, and nothing for regular files.

       -G, --no-group
              Inhibit display of group information in a long for-
              mat directory listing.

       -I, --ignorepattern
              Do not list files whose names match the shell  pat-
              tern  pattern  (not regular expression) unless they
              are given on the command line.  As in the shell, an
              initial `.' in a filename does not match a wildcard
              at the start of pattern.

       -L, --dereference
              List the  file  information  corresponding  to  the
              referrents  of  symbolic links rather for the links
              themselves.

       -N, --literal
              Do not quote file names.

       -Q, --quote-name
              Enclose file names in double quotes and quote  non-
              graphic characters as in C.

       -R, --recursive
              List the contents of all directories recursively.

       -S, --sort=size
              Sort  directory  contents  by  file size instead of
              alphabetically,  with  the  largest  files   listed
              first.

       -T, --tabsize cols
              Assume that each tabstop is cols columns wide.  The
              default is 8.  ls uses tabs where possible  in  the
              output, for efficiency. If cols is zero, do not use
              tabs at all.

       -U, --sort=none
              Do not sort directory contents; list them in  what-
              ever  order  they are stored on the disk. (The dif-
              ference between -Uand-f is that the former  doesn't
              disable or enable options.) This is especially use-
              ful when listing very large directories, since  not
              doing any sorting can be noticeably faster.

       -X, --sort=extension
              Sort  directory  contents  alphabetically  by  file
              extension (characters after the  last  `.');  files
              with no extension are sorted first.

       --color[=when]
              Specify  whether  to  use  color for distinguishing
              file types.  Colors are specified using the LS_COL-
              ORS  environment  variable.  For information on how
              to set this variable, see dircolors(1).   when  may
              be omitted, or one of:

              none   Do  not  use  color  at  all.  This  is  the
                     default.

              auto   Only use  color  if  standard  output  is  a
                     terminal.

              always Always use color.  Specifying --color and no
                     when is equivalent to --color=always.

       --full-time
              List times in full, rather than using the  standard
              abbreviation  heuristics. The format is the same as
              date(1)'s default;  it's  not  possible  to  change
              this,  but you can extract out the date string with
              cut(1) and then pass the result to `date -d'.

              This  is  most  useful  because  the  time   output
              includes the seconds.  (Unix filesystems store file
              timestamps only to  the  nearest  second,  so  this
              option  shows  all  the information there is.)  For
              example, this can help when  you  have  a  Makefile
              that is not regenerating files properly.

GNU STANDARD OPTIONS
       --help Print  a  usage message on standard output and exit
              successfully.

       --version
              Print version information on standard output,  then
              exit successfully.

       --     Terminate option list.

ENVIRONMENT
       The  variable  POSIXLY_CORRECT  determines  the  choice of
       unit.  If it is not set, then the variable TABSIZE  deter-
       mines  the  number  of  chars  per tab stop.  The variable
       COLUMNS (when it contains the representation of a  decimal
       integer)  determines the output column width (for use with
       the -C option).  Filenames must not be truncated  to  make
       them  fit  a  multi-column  output.   The  variables LANG,
       LC_ALL, LC_COLLATE, LC_CTYPE, LC_MESSAGES and LC_TIME have
       the  usual  meaning.   The variable TZ gives the time zone
       for time strings written by ls.  The variable LS_COLORS is
       used to specify the colors used.

BUGS
       On  BSD systems, the -s option reports sizes that are half
       the correct values for files that are NFS-mounted from HP-
       UX  systems.  On  HP-UX systems, ls reports sizes that are
       twice the correct values for files  that  are  NFS-mounted
       from  BSD systems. This is due to a flaw in HP-UX; it also
       affects the HP-UX ls program.

CONFORMING TO
       POSIX 1003.2

SEE ALSO
       dircolors(1)

NOTES
       This page describes ls  as  found  in  the  fileutils-3.16
       package;  other versions may differ slightly. Mail correc-
       tions and additions to aeb@cwi.nl and aw@mail1.bet1.puv.fi
       and  ragnar@lightside.ddns.org  .  Report bugs in the pro-
       gram to fileutils-bugs@gnu.ai.mit.edu.
前一個主題 | 下一個主題 | 頁首 | | |



Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|