ls命令的理解

ls注意只是显示文件的大小,不是占用磁盘空间,这句话主要是针对文件夹的,ls只是统计目录结构中文件夹结点的大小,而不是文件夹下所有文件的大小,统计文件夹下所有文件的总和,使用du命令,具体参考:http://blog.csdn.net/ysdaniel/article/details/6922055

du --max-depth=1,该命令可以查看当前文件夹的大小信息。

ll相当于ls -l,l.只显示隐藏的文件和目录,比如"."和".."

解释:文件修改时间,文件状态改变时间,文件访问时间
改变时间(change time)和修改时间(modification time),改变和修改之间的区别在于是改某个组件的标签还是更改它的内容。
访问时间(access time),访问时间是文件最后一次被读取的时间。因此阅读一个文件会更新它的访问时间,不过它的改变时间并没有变化(有关文件的信息没有被改变),它的修改时间也同样如此(文件本身没有被改变)。
具体解释:
st_atime
   Time when file data was last accessed. Changed by  the following   functions:   creat(),   mknod(), pipe(), utime(2), and read(2).

st_mtime
  Time when data was last modified. Changed by the  following  functions:  creat(), mknod(), pipe(), utime(), and write(2).

st_ctime
  Time when file status was last changed. Changed by the following   functions:   chmod(),   chown(),  creat(), link(2),  mknod(),  pipe(),  unlink(2),  utime(),  and write().

来源参考网址:http://blog.sina.com.cn/s/blog_67178440010101gr.html

按功能理解ls命令:
1、怎么显示,按行,按列,是否显示所属者或group等等
--author
  with -l, print the author of each file
参数-l已经能显示作者了,不知道为啥还需要这个参数

-C     list entries by columns
根据屏幕大小,按列显示检索结果,比如,总共可以分两行,则前两个作为第一列,第3、4个作为第二列,依次类推,类似下面:
1 3 5 7 9
2 4 6 8

--format=WORD
  across(横向)  -x, commas(横向显示按逗号分割) -m, horizontal(水平显示,即横向) -x, long(单行详细显示) -l, single-column(单行显示) -1, verbose(单行详细显示) -l, vertical(按列显示) -C

-l     use a long listing format
单行详细显示

-m     fill width with a comma separated list of entries
横向逗号显示

-n, --numeric-uid-gid
    like -l, but list numeric user and group IDs
显示所属者和组时,显示数字不显示名字

-x     list entries by lines instead of by columns
按一条线显示,不是按列显示,比如1 2 3 4,而不是
1 3
2 4

-1     list one file per line
单列显示

2、条件过滤显示
-a, --all
    do not ignore entries starting with .
不忽略“.”和“..”,就是不忽略“当前目录、父目录”的这两个特殊表示
-A, --almost-all
    do not list implied . and ..
忽略“当前目录、父目录”(即".","..")这两个特殊目录
-B, --ignore-backups
    do not list implied entries ending with ~
忽略备份文件,就是文件名最后带~的文件
-g     like -l, but do not list owner
单行详细显示,不显示所属者

-o     like -l, but do not list group information
单行详细显示,不显示组

-G, --no-group
    in a long listing, don’t print group names
不显示组,如果只用-G,不显示详细信息

--hide=PATTERN
  do  not  list implied entries matching shell PATTERN (overridden by -a or -A)
不显示匹配PATTERN的文件或文件夹,注意,这个参数会被-a和-A覆盖

-I, --ignore=PATTERN
    do not list implied entries matching shell PATTERN
这个和--hide相似,不过这个不会被-a和-A覆盖。

3、排序,按时间或名字,扩展名什么的排序,还有逆序设置什么的
-f     do not sort, enable -aU, disable -ls --color
-U     do not sort; list entries in directory order
不按某个参数排序,-f不理解,-U,说的按目录中的顺序,是按用界面化打开时显示的呢,还是按目录结构中存储的顺序情况,不太确定。

-c     with -lt: sort by, and show, ctime (time of last modification of file status information)
       with -l: show ctime and  sort  by  name
       otherwise: sort by ctime
-t表示文件列表按时间进行排序,默认是按文件内容的修改时间排序。
-c表示显示change(文件状态的改变时间)时间,不是内容修改时间。配合-t能实现按照文件状态的改变时间排序。如果没有-t,只是简单和-l,则显示状态改变时间,按文件名进行排序,如果-l和-t都没有搭配,则只是按change排序显示文件,不显示文件的详细信息。
其实可以简单理解-c是实现显示文件状态改变时间和按文件状态改变时间排序的基本。

-u     with -lt:  sort  by, and show, access time
       with -l: show access time and sort by name
       otherwise: sort by access time
类似-c,不过这个是访问时间,注意修改时间没有这样的表示,因为修改时间是默认选项,不需要可以写出。

--group-directories-first
              group directories before files.

              augment with a --sort option, but any use  of  --sort=none  (-U)
              disables grouping

-r, --reverse
    reverse order while sorting
逆序,即将原排序逆序显示。

-S  sort by file size
按文件大小
-t  sort by modification time
按修改时间
-v  natural sort of (version) numbers within text
按版本号
-X  sort alphabetically by entry extension
按扩展名的字母顺序

--sort=WORD
  sort by WORD instead of name: none -U, extension  -X,  size  -S,time -t, version -v
按各种参数进行排序

--time=WORD
  with -l,  show time as WORD instead of modification time: atime -u, access -u, use -u, ctime -c, or  status  -c;  use  specified time as sort key if --sort=time
感觉是-c和-u的综合表述。
注意多个时间综合在一起时,最后一个生效。

4、格式化时间的显示时间怎么显示
--full-time
  like -l --time-style=full-iso
单独这个参数会显示详细信息,其中时间的显示格式是:2015-01-16 15:40:55.811159015 +0800
--time-style=STYLE
  with  -l, show times using style STYLE: full-iso, long-iso, iso,locale, +FORMAT.  FORMAT is interpreted like ‘date’;  if  FORMAT is  FORMAT1<newline>FORMAT2, FORMAT1 applies to non-recent files and FORMAT2 to recent files; if STYLE is prefixed with ‘posix-’,STYLE takes effect only outside the POSIX locale
就是说设置时间显示的格式,重点说下FORMAT,第一点,不要忘了+,然后newline一般是一个变量形式,类似这样
newline='
'
ls -l --time-style="+%Y-%m-%d $newline%m-%d %H:%M"

时间的特殊符号表示:
‘%H’
    hour (‘00’...‘23’)
‘%I’
    hour (‘01’...‘12’)
‘%k’
    hour, space padded (‘ 0’...‘23’); equivalent to ‘%_H’. This is a GNU extension.
‘%l’
    hour, space padded (‘ 1’...‘12’); equivalent to ‘%_I’. This is a GNU extension.
‘%M’
    minute (‘00’...‘59’)
‘%N’
    nanoseconds (‘000000000’...‘999999999’). This is a GNU extension.
‘%p’
    locale's equivalent of either ‘AM’ or ‘PM’; blank in many locales. Noon is treated as ‘PM’ and midnight as ‘AM’.
‘%P’
    like ‘%p’, except lower case. This is a GNU extension.
‘%r’
    locale's 12-hour clock time (e.g., ‘11:11:04 PM’)
‘%R’
    24-hour hour and minute. Same as ‘%H:%M’.
‘%s’
    seconds since the epoch, i.e., since 1970-01-01 00:00:00 UTC. Leap seconds are not counted unless leap second support is available. See %s-examples, for examples. This is a GNU extension.
‘%S’
    second (‘00’...‘60’). This may be ‘60’ if leap seconds are supported.
‘%T’
    24-hour hour, minute, and second. Same as ‘%H:%M:%S’.
‘%X’
    locale's time representation (e.g., ‘23:13:48’)
‘%z’
    RFC 2822/ISO 8601 style numeric time zone (e.g., ‘-0600’ or ‘+0530’), or nothing if no time zone is determinable. This value reflects the numeric time zone appropriate for the current time, using the time zone rules specified by the TZ environment variable. The time (and optionally, the time zone rules) can be overridden by the --date option.
‘%:z’
    RFC 3339/ISO 8601 style numeric time zone with ‘:’ (e.g., ‘-06:00’ or ‘+05:30’), or nothing if no time zone is determinable. This is a GNU extension.
‘%::z’
    Numeric time zone to the nearest second with ‘:’ (e.g., ‘-06:00:00’ or ‘+05:30:00’), or nothing if no time zone is determinable. This is a GNU extension.
‘%:::z’
    Numeric time zone with ‘:’ using the minimum necessary precision (e.g., ‘-06’, ‘+05:30’, or ‘-04:56:02’), or nothing if no time zone is determinable. This is a GNU extension.
‘%Z’
    alphabetic time zone abbreviation (e.g., ‘EDT’), or nothing if no time zone is determinable. See ‘%z’ for how it is determined.

日期的特殊符号格式:
‘%a’
    locale's abbreviated weekday name (e.g., ‘Sun’)
‘%A’
    locale's full weekday name, variable length (e.g., ‘Sunday’)
‘%b’
    locale's abbreviated month name (e.g., ‘Jan’)
‘%B’
    locale's full month name, variable length (e.g., ‘January’)
‘%c’
    locale's date and time (e.g., ‘Thu Mar 3 23:05:25 2005’)
‘%C’
    century. This is like ‘%Y’, except the last two digits are omitted. For example, it is ‘20’ if ‘%Y’ is ‘2000’, and is ‘-0’ if ‘%Y’ is ‘-001’. It is normally at least two characters, but it may be more.
‘%d’
    day of month (e.g., ‘01’)
‘%D’
    date; same as ‘%m/%d/%y’
‘%e’
    day of month, space padded; same as ‘%_d’
‘%F’
    full date in ISO 8601 format; same as ‘%Y-%m-%d’. This is a good choice for a date format, as it is standard and is easy to sort in the usual case where years are in the range 0000...9999.
‘%g’
    year corresponding to the ISO week number, but without the century (range ‘00’ through ‘99’). This has the same format and value as ‘%y’, except that if the ISO week number (see ‘%V’) belongs to the previous or next year, that year is used instead.
‘%G’
    year corresponding to the ISO week number. This has the same format and value as ‘%Y’, except that if the ISO week number (see ‘%V’) belongs to the previous or next year, that year is used instead. It is normally useful only if ‘%V’ is also used; for example, the format ‘%G-%m-%d’ is probably a mistake, since it combines the ISO week number year with the conventional month and day.
‘%h’
    same as ‘%b’
‘%j’
    day of year (‘001’...‘366’)
‘%m’
    month (‘01’...‘12’)
‘%u’
    day of week (‘1’...‘7’) with ‘1’ corresponding to Monday
‘%U’
    week number of year, with Sunday as the first day of the week (‘00’...‘53’). Days in a new year preceding the first Sunday are in week zero.
‘%V’
    ISO week number, that is, the week number of year, with Monday as the first day of the week (‘01’...‘53’). If the week containing January 1 has four or more days in the new year, then it is considered week 1; otherwise, it is week 53 of the previous year, and the next week is week 1. (See the ISO 8601 standard.)
‘%w’
    day of week (‘0’...‘6’) with 0 corresponding to Sunday
‘%W’
    week number of year, with Monday as first day of week (‘00’...‘53’). Days in a new year preceding the first Monday are in week zero.
‘%x’
    locale's date representation (e.g., ‘12/31/99’)
‘%y’
    last two digits of year (‘00’...‘99’)
‘%Y’
    year. This is normally at least four characters, but it may be more. Year ‘0000’ precedes year ‘0001’, and year ‘-001’ precedes year ‘0000’.

参考网址:
http://www.gnu.org/software/coreutils/manual/html_node/date-invocation.html#date-invocation
http://www.gnu.org/software/coreutils/manual/html_node/Formatting-file-timestamps.html

5、显示文件大小格式的设置
--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.
设置信息列表中文件大小的显示格式

-h, --human-readable
  with -l, print sizes in human readable format (e.g., 1K 234M 2G)
设置易读的格式显示文件大小
--si  likewise, but use powers of 1000 not 1024
类似-h,不过进制按1000走,就是直接查小数点位数。
-k    like --block-size=1K
按K(1024)显示文件大小

-s, --size
    print the allocated size of each file, in blocks
按blocks数显示文件大小

6、文件种类的颜色设置
--color[=WHEN]
  colorize  the  output.   WHEN  defaults  to  ‘always’  or can be ‘never’ or ‘auto’. More info below。
  Using color to distinguish file types is disabled both by  default  and with  --color=never.  With --color=auto, ls emits color codes only when standard output is connected to a terminal.  The LS_COLORS  environment variable can change the settings.  Use the dircolors command to set it.
  没有深入了解,只是简单了解,显示颜色和禁止显示颜色。

7、文件名是否加特殊符号
-F, --classify
    append indicator (one of */=>@|) to entries
就是在文件名后面显示相应的符号,比如文件夹名后面就加“/”。

--file-type
  likewise, except do not append ‘*’
和-F相似,不过不追加“*”
-p, --indicator-style=slash
    append / indicator to directories
简单对文件夹进行追加“/”

--indicator-style=WORD
  append indicator with style WORD to entry names: none (default),slash (-p), file-type (--file-type), classify (-F)
对上面的简单总结概括。

-Q, --quote-name
  enclose entry names in double quotes
用双引号扩住文件名,比如"test"/
--quoting-style=WORD
  use  quoting style WORD for entry names: literal, locale, shell,shell-always, c, escape
扩文件名时的格式,比如单引号,双引号或者没有。

8、针对符号链接文件
-H, --dereference-command-line
    follow symbolic links listed on the command line

--dereference-command-line-symlink-to-dir
  follow each command line symbolic link that points to  a  directory
将符号链接对应的文件夹紧跟该链接,具体不知道什么意思,没有测试。

-L, --dereference
  when showing file information for a symbolic link, show information for the file the link references rather than for  the  link itself
显示文件信息时,不显示符号链接文件,而是显示符号链接对应文件的信息。

9、特殊字符的对待显示
-q, --hide-control-chars
    print ? instead of non graphic characters
用?代替非显示字符

  --show-control-chars
  show non graphic characters as-is  (default  unless  program  is ‘ls’ and output is a terminal)
不了解。

10、其他
-D, --dired
    generate output designed for Emacs’ dired mode
不明白什么意思。

-i, --inode
  print the index number of each file
显示结点的索引值。

-N, --literal
    print  raw entry names (don’t treat e.g. control characters specially)
不明白什么意思。

-T, --tabsize=COLS
    assume tab stops at each COLS instead of 8
-w, --width=COLS
    assume screen width instead of current value
这两个参数-T和-w设置时总是出错,不知道有什么特殊规则。

参考网址:

总体手册
http://www.gnu.org/software/coreutils/manual/
时间格式的符号表示
http://blog.chinaunix.net/uid-25525723-id-356633.html
http://www.gnu.org/software/coreutils/manual/html_node/Formatting-file-timestamps.html
ls显示的各项介绍
http://www.jb51.net/article/14709.htm
ll和l.命令

http://www.zhuitaiyang.com/html/2013/linuxchapter1_1005/415.html

访问时间,修改时间和改变时间的介绍

http://blog.sina.com.cn/s/blog_67178440010101gr.html

ls和du的区别

http://blog.csdn.net/ysdaniel/article/details/6922055


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值