文件有文件名与数据,在linux上被分为两个部分:用户数据(user data)与元数据(metadata)

用户数据,即文件数据块(data block),数据块是记录文件真实内容的地方,我们将其称为Block

元数据,即文件的附加属性,如文件大小,创建时间,所有者等信息,我们称其为Inode

在linux中,inode是文件元数据的一分部但其并不包含文件名,inode号即索引节点号,文件名仅是为了方便人们的记忆,

系统或程序通过正确的文件数据块。

ls命令详解

-a, --all

# 列出所有的文件,包括以“.“开头的隐藏文件(linux下文件隐藏文件是以.开头的,如果存在..代表存在着父目录)
[root@centos ~]#ls -la /data/
total 15364
drwxr-xr-x. 3 root root 50 Mar 27 18:46 .
dr-xr-xr-x. 19 root root 4096 Mar 27 11:32 ..
-rw-r--r-- 1 root root 5242880 Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root 10485760 Mar 27 18:38 testfile
[root@centos ~]#

-A, --almost-all

# 列出目录中除当前目录"."和父目录".."之外的所有文件列表
[root@centos ~]#ls -lA /data/
total 15360
-rw-r--r-- 1 root root 5242880 Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root 10485760 Mar 27 18:38 testfile
[root@centos ~]#

--author

# 配合-l,打印出每个文件的作者
[root@centos ~]#ls -l /data/
total 15360
-rw-r--r-- 1 root root 5242880 Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root 10485760 Mar 27 18:38 testfile
[root@centos ~]#ls -l --author /data/
total 15360
-rw-r--r-- 1 root root root 5242880 Mar 27 18:38 file.txt
drwxr-xr-x 2 root root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root root 10485760 Mar 27 18:38 testfile
[root@centos ~]#

-b, --escape

# 将文件中不可输出的字符以反斜线 " \ " 加字符编码的方式输出
ls -b

--block-size=SIZE

# 用指定特定的单位格式来列出文件和目录的大小
ls -l --block-size=K
ls -l --block-size=M

-B, --ignore-backups


# 列出目录中的文件,但是不显示备份文件,即那些文件名以"~"结尾的文件
ls -B

-c

# 与 -lt 选项连用时,按照文件状态时间排序输出目录内容,根据文件的索引节点中的 ctime 字段排序,与 -l 选项连用时,则排序的一句是文件的状态改变时间
[root@centos ~]#ls -l /data/
total 15360
-rw-r--r-- 1 root root 5242880 Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root 10485760 Mar 27 18:38 testfile
[root@centos ~]#ls -ltc /data/
total 15360
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root 5242880 Mar 27 18:38 file.txt
-rw-r--r-- 1 root root 10485760 Mar 27 18:38 testfile
[root@centos ~]#

-C

# 多列显示输出结果,默认选项
[root@centos ~]#ls /data/
file.txt logs testfile
[root@centos ~]#ls -C /data/
file.txt logs testfile
[root@centos ~]#

--color[=WHEN]

# 使用不同的颜色高亮显示不同的类型
ls --color=never
ls --color=auto
ls --color=always

-d, --directory

# 仅显示目录名,而不显示目录下的内容列表。显示符号链接文件本身,而不显示其所指向的目录列表
[root@centos ~]#ls -l /data/
total 15360
-rw-r--r-- 1 root root 5242880 Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root 10485760 Mar 27 18:38 testfile
[root@centos ~]#ls -ld /data/
drwxr-xr-x. 3 root root 50 Mar 27 18:46 /data/
[root@centos ~]#

-D, --dired

generate output designed for Emacs' dired mode

-f do not sort, enable -aU, disable -ls --color

-F, --classify

在每个输出项后追加文件的类型标识符,具体含义:
* 表示具有可执行权限的普通文件
/ 表示目录
@ 表示符号链接
| 表示命名管道 FIFO(First In First Out)
= 表示 sockets 套接字
当文件为普通文件时,不输出任何标识符
[root@centos ~]#ls -F1 /run/
NetworkManager/
agetty.reload
atd.pid
auditd.pid
console/
... 省略部分内容 ...
udev/
user/
utmp
[root@centos ~]#

--file-type

likewise, except do not append '*'

--format=WORD

# 以多种格式列出目录内容,如以逗号分隔、水平格式、长格式、垂直格式、交叉格式等列出
# 交叉
ls --format=across
# 逗号
ls --format=comma
# 水平
ls --format=horizontal
# 长格式
ls --format=long
# 单栏
ls --format=single-column
# 详情
ls --format=verbose
# 垂直
ls --format=vertical

--full-time:列出完整的日期与时间

like -l --time-style=full-iso
# 等于
ls -l --time-style=full-iso
# 示例
[root@centos /tmp]#ls -l --time-style=full-iso
total 16
-rw-r--r--. 1 root root 0 2021-03-25 14:21:20.744456987 +0800 14:21:20.log
-rw-r--r--. 1 root root 0 2021-03-25 14:21:37.077457392 +0800 2021-03-25.log
-rw-r--r--. 1 root root 12 2021-03-26 10:17:08.076137207 +0800 a.log
-rw-r--r--. 1 root root 12 2021-03-26 10:20:22.275142023 +0800 b.log
-rw-r--r--. 1 song root 0 2021-03-24 18:59:46.273586607 +0800 c.log
drwxr-xr-x. 2 root root 20 2021-03-25 14:23:14.837459816 +0800 console
-rw-r--r--. 1 root root 12 2021-03-26 10:29:36.934155776 +0800 d.log
-rwx------. 1 root root 1379 2021-03-24 12:23:57.576482018 +0800 ks-script-6_og6455
[root@centos /tmp]#

-g like -l, but do not list owner

# 等于 -l ,但不列出所有者
[root@centos ~]#ls -l /data/
total 15360
-rw-r--r-- 1 root root 5242880 Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root 10485760 Mar 27 18:38 testfile
[root@centos ~]#ls -g /data/
total 15360
-rw-r--r-- 1 root 5242880 Mar 27 18:38 file.txt
drwxr-xr-x 2 root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root 10485760 Mar 27 18:38 testfile
[root@centos ~]#

--group-directories-first

# 包含有很多文件和文件夹的目录,使目录名显示在文件名之前
ls --group-directories-first

-G, --no-group

# ls 命令在与'-G'和‘-l’选项一起将会使用长列表格式列出文件名称但是不带文件所属组名称
ls -lG

-h, --human-readable

# 配合 -l,以易读(人类可阅)的方式显示大小
ls -lh
# 注意: ‘-h’选项使用1024(计算机中的标准)的幂,文件或文件夹的大小分别以K,M和G作为输出单位。
[root@centos ~]#ls -l /data/
total 15360
-rw-r--r-- 1 root root 5242880 Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root 10485760 Mar 27 18:38 testfile
[root@centos ~]#ls -lh /data/
total 15M
-rw-r--r-- 1 root root 5.0M Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root 10M Mar 27 18:38 testfile
[root@centos ~]#

--si likewise, but use powers of 1000 not 1024

# 存在一个选项 ‘--si’与选项‘-h’相似,不同之处在于前者以使用1000的幂,后者使用1024的幂。
[root@centos ~]#ls -lh /data/
total 15M
-rw-r--r-- 1 root root 5.0M Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root 10M Mar 27 18:38 testfile
[root@centos ~]#ls -l --si /data/
total 16M
-rw-r--r-- 1 root root 5.3M Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root 11M Mar 27 18:38 testfile
[root@centos ~]#

-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
syt

--hide=PATTERN

do not list implied entries matching shell PATTERN (overridden by -a or -A)

--indicator-style=WORD

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

-i, --inode

# 显示文件索引节点号(inode),一个索引节点代表一个文件
[root@centos ~]#ls -li /data/logs/
total 131072
133 -rw-r--r-- 1 root root 20971520 Mar 27 18:38 time.log
131 -rw-r--r-- 1 root root 31457280 Mar 27 18:42 time1.log
135 -rw-r--r-- 1 root root 27262976 Mar 27 18:42 time2.log
137 -rw-r--r-- 1 root root 27262976 Mar 27 18:47 time3.log
138 -rw-r--r-- 1 root root 27262976 Mar 27 18:47 time4.log
[root@centos ~]#

-I, --ignore=PATTERN

#do not list implied entries matching shell PATTERN

-k like --block-size=1K

-l

# 以长格式显示目录下的内容列表。输出的信息从左到右依次包括文件名,文件类型,权限模式,硬链接数,所有者,组,文件大小和文件最后修改时间等
[root@centos ~]#ls -l /data/logs/
total 131072
-rw-r--r-- 1 root root 20971520 Mar 27 18:38 time.log
-rw-r--r-- 1 root root 31457280 Mar 27 18:42 time1.log
[root@centos ~]#

-L, --dereference

# 当显示符号链接的文件信息时,显示链接引用而不是链接本身的文件信息,列出文件的链接名

-m

# 用逗号分隔每个文件和目录的命令
[root@centos ~]#ls -m /data/logs/
time.log, time1.log, time2.log, time3.log, time4.log
[root@centos ~]# # 注意:
# linux的ls命令当与其选项‘-m’一起使用时可以在打印目录内容时以逗号‘,’分割。由于逗号分割的内容是水平填充的,ls命令不能在垂直列出内容时使用逗号来分割内容。
# 当使用长列表格式时,‘-m’选项就没有什么效果了。
[root@centos ~]#ls -m /data/logs/ -ltr
total 131072
-rw-r--r-- 1 root root 20971520 Mar 27 18:38 time.log
-rw-r--r-- 1 root root 31457280 Mar 27 18:42 time1.log
-rw-r--r-- 1 root root 27262976 Mar 27 18:42 time2.log
-rw-r--r-- 1 root root 27262976 Mar 27 18:47 time3.log
-rw-r--r-- 1 root root 27262976 Mar 27 18:47 time4.log
[root@centos ~]#

-n, --numeric-uid-gid

# 已用户识别码和群组织代替其名称
[root@centos ~]#ls -l /data/logs/
total 131072
-rw-r--r-- 1 root root 20971520 Mar 27 18:38 time.log
-rw-r--r-- 1 root root 31457280 Mar 27 18:42 time1.log
-rw-r--r-- 1 root root 27262976 Mar 27 18:42 time2.log
-rw-r--r-- 1 root root 27262976 Mar 27 18:47 time3.log
-rw-r--r-- 1 root root 27262976 Mar 27 18:47 time4.log
[root@centos ~]#ls -n /data/logs/ # 以数字 0 代替 root
total 131072
-rw-r--r-- 1 0 0 20971520 Mar 27 18:38 time.log
-rw-r--r-- 1 0 0 31457280 Mar 27 18:42 time1.log
-rw-r--r-- 1 0 0 27262976 Mar 27 18:42 time2.log
-rw-r--r-- 1 0 0 27262976 Mar 27 18:47 time3.log
-rw-r--r-- 1 0 0 27262976 Mar 27 18:47 time4.log
[root@centos ~]#

-N, --literal

print raw entry names (don't treat e.g. control characters specially)

-o like -l, but do not list group information

-p, --indicator-style=slash

append / indicator to directories

-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)

-Q, --quote-name

# 解释:将ls命令的输出内容用双引号引起来
[root@centos ~]#ls -1 /data/
file.txt
logs
testfile
[root@centos ~]#ls -1Q /data/
"file.txt"
"logs"
"testfile"
[root@centos ~]#

--quoting-style=WORD

use quoting style WORD for entry names: literal, locale, shell, shell-always, c, escape

-r, --reverse

# 以倒叙(逆序)方式显示文件和目录
[root@centos ~]#ls -ltr /data/
total 15360
-rw-r--r-- 1 root root 10485760 Mar 27 18:38 testfile
-rw-r--r-- 1 root root 5242880 Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
[root@centos ~]#

-R, --recursive

# 递归处理,将指定目录下的所有文件及子目录一并显示
[root@centos ~]#tree /data/
/data/
|-- file.txt
|-- logs
| |-- time.log
| |-- time1.log
| |-- time2.log
| |-- time3.log
| `-- time4.log
`-- testfile 1 directory, 7 files
[root@centos ~]#ls -lR /data/
/data/:
total 15360
-rw-r--r-- 1 root root 5242880 Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root 10485760 Mar 27 18:38 testfile /data/logs:
total 131072
-rw-r--r-- 1 root root 20971520 Mar 27 18:38 time.log
-rw-r--r-- 1 root root 31457280 Mar 27 18:42 time1.log
-rw-r--r-- 1 root root 27262976 Mar 27 18:42 time2.log
-rw-r--r-- 1 root root 27262976 Mar 27 18:47 time3.log
-rw-r--r-- 1 root root 27262976 Mar 27 18:47 time4.log
[root@centos ~]#

-s, --size

# 以区块的形式显示每个文件和目录的大小
[root@centos ~]#ls -s /data/
total 15360
5120 file.txt 0 logs 10240 testfile
[root@centos ~]#du -sh /data/
143M /data/
[root@centos ~]#

-S sort by file size

# 按文件大小(从大到小)的顺序排序
[root@centos ~]#ls -l /data/
total 15360
-rw-r--r-- 1 root root 5242880 Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
-rw-r--r-- 1 root root 10485760 Mar 27 18:38 testfile
[root@centos ~]#ls -lsSr /data/
total 15360
0 drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
5120 -rw-r--r-- 1 root root 5242880 Mar 27 18:38 file.txt
10240 -rw-r--r-- 1 root root 10485760 Mar 27 18:38 testfile
[root@centos ~]#

--sort=WORD

# 根据扩展名、大小、时间和版本对目录内容排序。
# 我们可以使用--extension选项来按照扩展名对输出结果排序,--size扩展选项按照大小排序,-t扩展选项按照时间排序,-v扩展选项对版本排序。
# 我们也可以使用--none选项,它会以常规方式输出结果而不会进行排序。
ls --sort=extension
ls --sort=size
ls --sort=time
ls --sort=version
ls --sort=none

--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

--time-style=STYLE


# Linux使用ls命令时,ls -l 默认只显示“月-日”,而不显示“年”,这样就给我们查看文件的时间属性带来困扰,这时侯,我们可以指定time-style(时间显示类型)
# STYLE:full-iso,long-iso,iso,locale,+%H:%M:%S:%D
# 注意 - 在上面行中,H(时),M(分),S(秒),D(日)的顺序可以任意调整。此外,你只需选择那些相关的选项,而不是所有选项。 # 将只显示小时
ls -l --time-style=+%H # 将显示小时、分钟和日
ls -l --time-style=+%H:%M:%D
ls -l --time-style="+%Y-%m-%d $newline%m-%d %H:%M"
ls -l --time-style="+%b %e %Y$newline%b %e %H:%M"
ls -l --time-style="iso"
ls -l --time-style="locale"
ls -l --time-style=full-iso
ls -l --time-style=long-iso
ls --full-time

--time-style示例:

function check_log()
{
path=/search/miquery
n=`ls $path/log/ie_log/ie_log -l --time-style=+%s | awk '{print $6}'`
def=$((`date +%s` - $n))
#300s内不滚动则报警
if [ $def -gt 300 ]
then
sendMsg "MiQuery logroll stop"
fi
}

-t

# 按文件和目录的更改时间排序
[root@centos ~]#ls -ltr /data/
total 15360
-rw-r--r-- 1 root root 10485760 Mar 27 18:38 testfile
-rw-r--r-- 1 root root 5242880 Mar 27 18:38 file.txt
drwxr-xr-x 2 root root 90 Mar 27 18:47 logs
[root@centos ~]#

-T, --tabsize=COLS

# 通过ls命令为列出的目录内容手动指定的制表符大小而不是默认的8

ls --tabsize=4

-u with -lt: sort by, and show, access time with -l: show access time and sort by name otherwise: sort by access time

-U do not sort; list entries in directory order

-v natural sort of (version) numbers within text

-w, --width=COLS

# 标准输出结果中打印目录内容中比默认指定的更多栏目。
# 我们可以手动分配屏幕宽度的值和出现的栏目的控制数。这可以通过使用‘--width’开关实现。
#命令:
ls --width 80
ls --width 100
ls --width 150

-x list entries by lines instead of by columns

-X sort alphabetically by entry extension

-1

# 与 -C 选项功能相反,所有输出信息用单列格式输出,不输出为多列
[root@centos ~]#ls -C /data/logs/
time.log time1.log time2.log time3.log time4.log
[root@centos ~]#
[root@centos ~]#ls -1 /data/logs/
time.log
time1.log
time2.log
time3.log
time4.log
[root@centos ~]#

SELinux options:

--lcontext

Display security context.   Enable -l. Lines will probably be too wide for most displays.

-Z, --context

Display security context so it fits on most displays.  Displays only mode, user, group, security context and file name.

--help

# 显示帮助信息
[root@centos ~]#ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified. Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-A, --almost-all do not list implied . and ..
--author with -l, print the author of each file

--version

# 输出版本信息并退出
[root@centos ~]#ls --version
ls (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Written by Richard M. Stallman and David MacKenzie.
[root@centos ~]#

ls(list)命令详解及生产使用示例的更多相关文章

  1. 【转载】linux ls -l命令详解

    Linux 文件或目录的属性主要包括:文件或目录的节点.种类.权限模式.链接数量.所归属的用户和用户组.最近访问或修改的时间等内容.具体情况如下: 命令: ls -lih 输出: [root@loca ...

  2. ls -l命令详解

    输入: ls -l 输出: -rwxr-xr-x root root May : b 第一个字段(1个字符):文件类型 - :普通文件 d:目录文件 b:块设备文件(block) c:字符设备文件(c ...

  3. Linux curl 命令详解

    命令概要 该命令设计用于在没有用户交互的情况下工作. curl 是一个工具,用于传输来自服务器或者到服务器的数据.「向服务器传输数据或者获取来自服务器的数据」 可支持的协议有(DICT.FILE.FT ...

  4. Linux命令详解之–ls命令

    今天开始为大家介绍下Linux中常用的命令,首先给大家介绍下Linux中使用频率最高的命令--ls命令. 更多Linux命令详情请看:Linux命令速查手册 linux ls命令用于显示指定工作目录下 ...

  5. Linux就业技术指导(五):Linux运维核心管理命令详解

    一,Linux核心进程管理命令 1.1 ps:查看进程 1.1.1 命令解释 功能说明 ps命令用于列出执行ps命令的那个时刻的进程快照,就像用手机给进程照了一张照片.如果想要动态地显示进程,就需要使 ...

  6. 云计算:Linux运维核心管理命令详解

    云计算:Linux运维核心管理命令详解 想做好运维工作,人先要学会勤快: 居安而思危,勤记而补拙,方可不断提高: 别人资料不论你用着再如何爽那也是别人的: 自己总结东西是你自身特有的一种思想与理念的展 ...

  7. Kubernetes,kubectl常用命令详解

    kubectl概述 祭出一张图,转载至 kubernetes-handbook/kubectl命令概述 ,可以对命令族有个整体的概念. 环境准备 允许master节点部署pod,使用命令如下: kub ...

  8. Docker命令详解

    Docker命令详解   最近学习Docker,将docker所有命令实验了一番,特整理如下: # docker --help Usage: docker [OPTIONS] COMMAND [arg ...

  9. linux awk命令详解

    linux awk命令详解 简介 awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大.简单来说awk就是把文件逐行的读入,以空格为默认分 ...

随机推荐

  1. ruby & rvm

    ruby & rvm https://rvm.io/ Ruby Version Manager (RVM) RVM is a command-line tool which allows yo ...

  2. @bind decorator

    @bind decorator https://www.npmjs.com/package/bind-decorator https://github.com/NoHomey/bind-decorat ...

  3. Flutter 使用 flare

    video flare_flutter 工作示例 install dependencies: flare_flutter: ^1.5.5 assets: - assets/flr/switch_day ...

  4. 云服务器Centos7部署Tomcat服务器

    目录 部署Tomcat服务器 1.安装JDK1.8 2.安装与启动tomcat 配置安全组(8080端口) 参考文章 部署Tomcat服务器 1.安装JDK1.8 JDK下载地址:https://ww ...

  5. 我ssh框架遇到报错及处理方式

    Exception encountered during context initialization - cancelling refresh attempt 修改hbm.xml后遇到的问题,错误可 ...

  6. Filter理解

    web中Filter通过<init-param>添加参数.web.xml中的配置: <filter> <filter-name>AuthFilter</fil ...

  7. mui调用本地相册调用相机上传照片

    调用mui的常用库和jquery html部分: <header class="mui-bar mui-bar-nav"> <a class="mui- ...

  8. HashMap是如何进行扩容的?

    HashMap通过resize()方法进行扩容. 源码解析: resize()函数有两种使用情况: 一.当table数组为null时初始化hash表. 二.当table数组不为null时进行扩容. 1 ...

  9. Android 开发学习进程0.28 腾讯TBS接入和相关问题

    TBS 的接入和使用 TBS 的接入 腾讯TBS是X5内核的升级版,可以当作webview 来打开 网页,可以以用来打开docx doc pdf 等文件,这里主要使用的是文件功能. 依赖接入 api ...

  10. DRF 三大认证之身份认证

    目录 路由组件补充 三大认证 一.身份认证 1.如何进行身份认证 2.jwt认证规则原理 3.jwt的组成 4.jwt的使用方法 4.1 签发算法 4.2 校验算法 4.3 刷新算法 二.权限认证 三 ...