Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1127885
  • 博文数量: 113
  • 博客积分: 2422
  • 博客等级: 大尉
  • 技术积分: 1393
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-25 17:54
文章分类
文章存档

2016年(1)

2014年(8)

2013年(7)

2012年(13)

2011年(42)

2010年(26)

2009年(6)

2008年(6)

2007年(4)

我的朋友

分类: LINUX

2012-01-04 20:19:56

Linux中查见的ls命令,但凡使用过linux的朋友都会明白这个命令的用处,对于这个常用的命令,我们平时可能只是使用一些简单的参数,今天有空man ls看了一下说明,看似简单的命令中还是有许多的参数可以简化的我们的工作,提高效率的。

注:本实例在REDHAT上实现的,我的机器版本如下:
mounix.com$ cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
mounix.com$

ls命令中有一个-S的参数,主要是用来排序的,要与-l命令一同使用。

具体说明见下面的man手册
       -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
              with -l, show time as WORD instead of modification time: atime, access, use, ctime or
              status; use specified time as sort key if --sort=time
       --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 FORMAT1FORMAT2, 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

其中的--time-style 参数可以让我们定义输出的时间格式,格式的写法与date中的写法一致。

下面是实例:
m$ date "+%Y-%m-%d %H:%M:%S"
2012-01-04 20:34:28
mounix.com$ cd /
m$ ls -dlS --time-style="+%Y-%m-%d %H:%M:%S" *
drwx------   2 root root 16384 2011-08-25 00:49:26 lost+found
drwxr-xr-x 109 root root 12288 2012-01-02 04:04:10 etc
drwxr-xr-x   2 root root 12288 2011-08-24 18:19:07 sbin
drwxr-xr-x   2 root root  4096 2011-11-30 09:26:00 bin
drwxr-xr-x  10 root root  4096 2011-12-23 09:08:31 data
drwxr-xr-x   9 root root  4096 2011-12-13 11:38:02 home
drwxr-xr-x  11 root root  4096 2011-08-24 18:18:47 lib
drwxr-xr-x   7 root root  4096 2011-08-24 18:18:47 lib64
drwxr-xr-x   4 root root  4096 2011-12-13 18:09:18 macro
drwxr-xr-x   2 root root  4096 2008-08-08 23:26:51 media
drwxr-xr-x   2 root root  4096 2009-07-29 21:34:57 misc
drwxr-xr-x   2 root root  4096 2008-08-08 23:26:51 mnt
drwxr-xr-x   4 root root  4096 2011-11-30 09:25:16 opt
drwxr-x---  22 root root  4096 2011-12-23 14:57:58 root
drwxr-xr-x   2 root root  4096 2011-08-24 16:50:04 selinux
drwxr-xr-x   2 root root  4096 2008-08-08 23:26:51 srv
drwxr-xr-x   3 root root  4096 2011-08-24 16:57:15 tftpboot
drwxrwxrwt   7 root root  4096 2012-01-04 14:13:48 tmp
drwxr-xr-x  16 root root  4096 2011-08-26 09:25:20 usr
drwxr-xr-x  26 root root  4096 2011-11-30 09:25:25 var
drwxr-xr-x  14 root root  4000 2011-10-25 16:36:04 dev
drwxr-xr-x   4 root root  1024 2011-08-24 16:55:03 boot
dr-xr-xr-x 151 root root     0 2011-08-25 01:09:20 proc
drwxr-xr-x  11 root root     0 2011-08-25 01:09:23 sys
m$ pwd
/
m$

阅读(5895) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~