跳转至

ls 命令


2014-02-16 by dongnan

举个栗子

日期和时间的格式按统一的格式列出来

ls -lt --time-style=long-iso
drwxr-xr-x 2 root root 4096 2013-11-02 19:44 210
drwxr-xr-x 2 root root 4096 2013-11-02 19:44 101

ls -lt --time-style="+%Y-%m-%d_%H:%M"
drwxr-xr-x 2 root root 4096 2013-11-02_19:44 210
drwxr-xr-x 2 root root 4096 2013-11-02_19:44 101

按文件大小排序

# 详细信息
ls -l

total 12004
-rw-------. 1 root root     1503 Mar 18 02:46 anaconda-ks.cfg
-rw-r--r--. 1 root root   30152 Mar 18 02:46 install.log
-rw-r--r--. 1 root root     7572 Mar 18 02:44 install.log.syslog
-rw-r--r--  1 root root 12240534 Mar 19 02:30 salt-rpm.tar.gz

# 更好的可读性
ls -lh

total 12M
-rw-------. 1 root root 1.5K Mar 18 02:46 anaconda-ks.cfg
-rw-r--r--. 1 root root  30K Mar 18 02:46 install.log
-rw-r--r--. 1 root root 7.4K Mar 18 02:44 install.log.syslog
-rw-r--r--  1 root root  12M Mar 19 02:30 salt-rpm.tar.gz

# 按文件大小排序
ls -lhS

total 12M
-rw-r--r--  1 root root  12M Mar 19 02:30 salt-rpm.tar.gz
-rw-r--r--. 1 root root  30K Mar 18 02:46 install.log
-rw-r--r--. 1 root root 7.4K Mar 18 02:44 install.log.syslog
-rw-------. 1 root root 1.5K Mar 18 02:46 anaconda-ks.cfg

命令参数

NAME
       ls - list directory contents

SYNOPSIS
       ls [OPTION]... [FILE]...

DESCRIPTION
       List information about the FILEs (the current directory by default).  
       Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.


-l     use a long listing format

-t     sort by modification time, newest first

-S     sort by file size

-h, --human-readable
      with -l, print sizes in human readable format (e.g., 1K 234M 2G)

--time-style=STYLE
      with  -l,  show  times  using  style  STYLE:  full-iso,  long-iso, iso, locale, or +FORMAT; 
      ....



回到页面顶部