Linux常用命令——ls命令

这篇具有很好参考价值的文章主要介绍了Linux常用命令——ls命令。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

在线Linux命令查询工具

ls

显示目录内容列表

补充说明

ls命令用来显示目标列表,在Linux中是使用率较高的命令。ls命令的输出信息可以进行彩色加亮显示,以分区不同类型的文件。

语法

ls(选项)(参数)

选项

-a, --all        # 不隐藏任何以. 开始的项目
-A, --almost-all #   列出除. 及.. 以外的任何项目
    --author     # 与-l 同时使用时列出每个文件的作者
-b, --escape     # 以八进制溢出序列表示不可打印的字符
    --block-size=SIZE   #   scale sizes by SIZE before printing them; e.g.,
                        #     '--block-size=M' prints sizes in units of
                        #     1,048,576 bytes; see SIZE format below
-B, --ignore-backups    #   do not list implied entries ending with ~
-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, newest first
-C                      #   list entries by columns
    --color[=WHEN]      #   colorize the output; WHEN can be 'never', 'auto',
                        #     or 'always' (the default); more info below
-d, --directory         #   list directories themselves, not their contents
-D, --dired             #   generate output designed for Emacs' dired mode
-f                      #   do not sort, enable -aU, disable -ls --color
-F, --classify          #   append indicator (one of */=>@|) to entries
    --file-type         #   likewise, except do not append '*'
    --format=WORD       #   across -x, commas -m, horizontal -x, long -l,
                        #     single-column -1, verbose -l, vertical -C
    --full-time         #   like -l --time-style=full-iso
-g        # 类似-l,但不列出所有者
    --group-directories-first
                        #  group directories before files;
                        #    can be augmented with a --sort option, but any
                        #    use of --sort=none (-U) disables grouping
-G, --no-group          # 以一个长列表的形式,不输出组名
-h, --human-readable    # 与-l 一起,以易于阅读的格式输出文件大小
      (例如 1K 234M 2G)
    --si      # 同上面类似,但是使用1000 为基底而非1024
-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
    --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              #  print the index number of each file
-I, --ignore=PATTERN     #  do not list implied entries matching shell PATTERN
-k, --kibibytes          #  default to 1024-byte blocks for disk usage
-l                #  使用较长格式列出信息
-L, --dereference #  当显示符号链接的文件信息时,显示符号链接所指示
     # 的对象而并非符号链接本身的信息
-m   #     所有项目以逗号分隔,并填满整行行宽
-n, --numeric-uid-gid #  类似 -l,但列出UID 及GID 号
-N, --literal  #   输出未经处理的项目名称 (如不特别处理控制字符)
-o       # 类似 -l,但不列出有关组的信息
-p,  --indicator-style=slash # 对目录加上表示符号"/"
-q, --hide-control-chars #  print ? instead of nongraphic characters
    --show-control-chars #  show nongraphic characters as-is (the default,
                         #    unless program is 'ls' and output is a terminal)
-Q, --quote-name         #  enclose entry names in double quotes
    --quoting-style=WORD #  use quoting style WORD for entry names:
                         #    literal, locale, shell, shell-always, c, escape
-r, --reverse   #  逆序排列
-R, --recursive #  递归显示子目录
-s, --size      #  以块数形式显示每个文件分配的尺寸
-S                      #   sort by file size
    --sort=WORD         #   sort by WORD instead of name: none (-U), size (-S),
                        #     time (-t), version (-v), extension (-X)
    --time=WORD         #   with -l, show time as WORD instead of default
                        #     modification time: atime or access or use (-u)
                        #     ctime or status (-c); also 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, or +FORMAT;
                        #     FORMAT is interpreted like in 'date'; if FORMAT
                        #     is FORMAT1<newline>FORMAT2, then 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
-t                      #   sort by modification time, newest first
-T, --tabsize=COLS      #   assume tab stops at each COLS instead of 8
-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        #   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

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.
--scontext              #   Display only security context and file name.
    --help    # 显示此帮助信息并退出
    --version # 显示版本信息并退出

参数

目录:指定要显示列表的目录,也可以是具体的文件。

实例

$ ls       # 仅列出当前目录可见文件
$ ls -l    # 列出当前目录可见文件详细信息
$ ls -hl   # 列出详细信息并以可读大小显示文件大小
$ ls -al   # 列出所有文件(包括隐藏)的详细信息

显示当前目录下包括影藏文件在内的所有文件列表

[root@localhost ~]# ls -a
.   anaconda-ks.cfg  .bash_logout   .bashrc  install.log         .mysql_history  satools  .tcshrc   .vimrc
..  .bash_history    .bash_profile  .cshrc   install.log.syslog  .rnd            .ssh     .viminfo

输出长格式列表

[root@localhost ~]# ls -1

anaconda-ks.cfg
install.log
install.log.syslog
satools

显示文件的inode信息
索引节点(index inode简称为“inode”)是Linux中一个特殊的概念,具有相同的索引节点号的两个文本本质上是同一个文件(除文件名不同外)。

[root@localhost ~]# ls -i -l anaconda-ks.cfg install.log
2345481 -rw------- 1 root root   859 Jun 11 22:49 anaconda-ks.cfg
2345474 -rw-r--r-- 1 root root 13837 Jun 11 22:49 install.log

水平输出文件列表

[root@localhost /]# ls -m

bin, boot, data, dev, etc, home, lib, lost+found, media, misc, mnt, opt, proc, root, sbin, selinux, srv, sys, tmp, usr, var

修改最后一次编辑的文件
最近修改的文件显示在最上面。

[root@localhost /]# ls -t

tmp  root  etc  dev  lib  boot  sys  proc  data  home  bin  sbin  usr  var  lost+found  media  mnt  opt  selinux  srv  misc

显示递归文件

[root@localhost ~]# ls -R
.:
anaconda-ks.cfg  install.log  install.log.syslog  satools

./satools:
black.txt  freemem.sh  iptables.sh  lnmp.sh  mysql  php502_check.sh  ssh_safe.sh

打印文件的UID和GID

[root@localhost /]# ls -n

total 254
drwxr-xr-x   2 0 0  4096 Jun 12 04:03 bin
drwxr-xr-x   4 0 0  1024 Jun 15 14:45 boot
drwxr-xr-x   6 0 0  4096 Jun 12 10:26 data
drwxr-xr-x  10 0 0  3520 Sep 26 15:38 dev
drwxr-xr-x  75 0 0  4096 Oct 16 04:02 etc
drwxr-xr-x   4 0 0  4096 Jun 12 10:26 home
drwxr-xr-x  14 0 0 12288 Jun 16 04:02 lib
drwx------   2 0 0 16384 Jun 11 22:46 lost+found
drwxr-xr-x   2 0 0  4096 May 11  2011 media
drwxr-xr-x   2 0 0  4096 Nov  8  2010 misc
drwxr-xr-x   2 0 0  4096 May 11  2011 mnt
drwxr-xr-x   2 0 0  4096 May 11  2011 opt
dr-xr-xr-x 232 0 0     0 Jun 15 11:04 proc
drwxr-x---   4 0 0  4096 Oct 15 14:43 root
drwxr-xr-x   2 0 0 12288 Jun 12 04:03 sbin
drwxr-xr-x   2 0 0  4096 May 11  2011 selinux
drwxr-xr-x   2 0 0  4096 May 11  2011 srv
drwxr-xr-x  11 0 0     0 Jun 15 11:04 sys
drwxrwxrwt   3 0 0 98304 Oct 16 08:45 tmp
drwxr-xr-x  13 0 0  4096 Jun 11 23:38 usr
drwxr-xr-x  19 0 0  4096 Jun 11 23:38 var

列出文件和文件夹的详细信息

[root@localhost /]# ls -l

total 254
drwxr-xr-x   2 root root  4096 Jun 12 04:03 bin
drwxr-xr-x   4 root root  1024 Jun 15 14:45 boot
drwxr-xr-x   6 root root  4096 Jun 12 10:26 data
drwxr-xr-x  10 root root  3520 Sep 26 15:38 dev
drwxr-xr-x  75 root root  4096 Oct 16 04:02 etc
drwxr-xr-x   4 root root  4096 Jun 12 10:26 home
drwxr-xr-x  14 root root 12288 Jun 16 04:02 lib
drwx------   2 root root 16384 Jun 11 22:46 lost+found
drwxr-xr-x   2 root root  4096 May 11  2011 media
drwxr-xr-x   2 root root  4096 Nov  8  2010 misc
drwxr-xr-x   2 root root  4096 May 11  2011 mnt
drwxr-xr-x   2 root root  4096 May 11  2011 opt
dr-xr-xr-x 232 root root     0 Jun 15 11:04 proc
drwxr-x---   4 root root  4096 Oct 15 14:43 root
drwxr-xr-x   2 root root 12288 Jun 12 04:03 sbin
drwxr-xr-x   2 root root  4096 May 11  2011 selinux
drwxr-xr-x   2 root root  4096 May 11  2011 srv
drwxr-xr-x  11 root root     0 Jun 15 11:04 sys
drwxrwxrwt   3 root root 98304 Oct 16 08:48 tmp
drwxr-xr-x  13 root root  4096 Jun 11 23:38 usr
drwxr-xr-x  19 root root  4096 Jun 11 23:38 var

列出可读文件和文件夹详细信息

[root@localhost /]# ls -lh

total 254K
drwxr-xr-x   2 root root 4.0K Jun 12 04:03 bin
drwxr-xr-x   4 root root 1.0K Jun 15 14:45 boot
drwxr-xr-x   6 root root 4.0K Jun 12 10:26 data
drwxr-xr-x  10 root root 3.5K Sep 26 15:38 dev
drwxr-xr-x  75 root root 4.0K Oct 16 04:02 etc
drwxr-xr-x   4 root root 4.0K Jun 12 10:26 home
drwxr-xr-x  14 root root  12K Jun 16 04:02 lib
drwx------   2 root root  16K Jun 11 22:46 lost+found
drwxr-xr-x   2 root root 4.0K May 11  2011 media
drwxr-xr-x   2 root root 4.0K Nov  8  2010 misc
drwxr-xr-x   2 root root 4.0K May 11  2011 mnt
drwxr-xr-x   2 root root 4.0K May 11  2011 opt
dr-xr-xr-x 235 root root    0 Jun 15 11:04 proc
drwxr-x---   4 root root 4.0K Oct 15 14:43 root
drwxr-xr-x   2 root root  12K Jun 12 04:03 sbin
drwxr-xr-x   2 root root 4.0K May 11  2011 selinux
drwxr-xr-x   2 root root 4.0K May 11  2011 srv
drwxr-xr-x  11 root root    0 Jun 15 11:04 sys
drwxrwxrwt   3 root root  96K Oct 16 08:49 tmp
drwxr-xr-x  13 root root 4.0K Jun 11 23:38 usr
drwxr-xr-x  19 root root 4.0K Jun 11 23:38 var

显示文件夹信息

[root@localhost /]# ls -ld /etc/

drwxr-xr-x 75 root root 4096 Oct 16 04:02 /etc/

按时间列出文件和文件夹详细信息

[root@localhost /]# ls -lt

total 254
drwxrwxrwt   3 root root 98304 Oct 16 08:53 tmp
drwxr-xr-x  75 root root  4096 Oct 16 04:02 etc
drwxr-x---   4 root root  4096 Oct 15 14:43 root
drwxr-xr-x  10 root root  3520 Sep 26 15:38 dev
drwxr-xr-x  14 root root 12288 Jun 16 04:02 lib
drwxr-xr-x   4 root root  1024 Jun 15 14:45 boot
drwxr-xr-x  11 root root     0 Jun 15 11:04 sys
dr-xr-xr-x 232 root root     0 Jun 15 11:04 proc
drwxr-xr-x   6 root root  4096 Jun 12 10:26 data
drwxr-xr-x   4 root root  4096 Jun 12 10:26 home
drwxr-xr-x   2 root root  4096 Jun 12 04:03 bin
drwxr-xr-x   2 root root 12288 Jun 12 04:03 sbin
drwxr-xr-x  13 root root  4096 Jun 11 23:38 usr
drwxr-xr-x  19 root root  4096 Jun 11 23:38 var
drwx------   2 root root 16384 Jun 11 22:46 lost+found
drwxr-xr-x   2 root root  4096 May 11  2011 media
drwxr-xr-x   2 root root  4096 May 11  2011 mnt
drwxr-xr-x   2 root root  4096 May 11  2011 opt
drwxr-xr-x   2 root root  4096 May 11  2011 selinux
drwxr-xr-x   2 root root  4096 May 11  2011 srv
drwxr-xr-x   2 root root  4096 Nov  8  2010 misc

按修改时间列出文件和文件夹详细信息

[root@localhost /]# ls -ltr

total 254
drwxr-xr-x   2 root root  4096 Nov  8  2010 misc
drwxr-xr-x   2 root root  4096 May 11  2011 srv
drwxr-xr-x   2 root root  4096 May 11  2011 selinux
drwxr-xr-x   2 root root  4096 May 11  2011 opt
drwxr-xr-x   2 root root  4096 May 11  2011 mnt
drwxr-xr-x   2 root root  4096 May 11  2011 media
drwx------   2 root root 16384 Jun 11 22:46 lost+found
drwxr-xr-x  19 root root  4096 Jun 11 23:38 var
drwxr-xr-x  13 root root  4096 Jun 11 23:38 usr
drwxr-xr-x   2 root root 12288 Jun 12 04:03 sbin
drwxr-xr-x   2 root root  4096 Jun 12 04:03 bin
drwxr-xr-x   4 root root  4096 Jun 12 10:26 home
drwxr-xr-x   6 root root  4096 Jun 12 10:26 data
dr-xr-xr-x 232 root root     0 Jun 15 11:04 proc
drwxr-xr-x  11 root root     0 Jun 15 11:04 sys
drwxr-xr-x   4 root root  1024 Jun 15 14:45 boot
drwxr-xr-x  14 root root 12288 Jun 16 04:02 lib
drwxr-xr-x  10 root root  3520 Sep 26 15:38 dev
drwxr-x---   4 root root  4096 Oct 15 14:43 root
drwxr-xr-x  75 root root  4096 Oct 16 04:02 etc
drwxrwxrwt   3 root root 98304 Oct 16 08:54 tmp

按照特殊字符对文件进行分类

[root@localhost nginx-1.2.1]# ls -F

auto/  CHANGES  CHANGES.ru  conf/  configure*  contrib/  html/  LICENSE  Makefile  man/  objs/  README  src/

列出文件并标记颜色分类

[root@localhost nginx-1.2.1]# ls --color=auto

auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src

在线Linux命令查询工具

linux ls,Linux命令,linux,运维,服务器
原文链接文章来源地址https://www.toymoban.com/news/detail-740437.html

到了这里,关于Linux常用命令——ls命令的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Python 与机器学习,在服务器使用过程中,常用的 Linux 命令包括哪些?

    🍉 CSDN 叶庭云 : https://yetingyun.blog.csdn.net/ 本博客旨在分享在实际开发过程中,开发者需要了解并熟练运用的 Linux 操作系统常用命令。Linux 作为一种操作系统,与 Windows 或 MacOS 并驾齐驱,尤其在服务器和开发环境中占据重要地位。Linux 命令,简而言之,就是指导计算机执行

    2024年04月12日
    浏览(44)
  • Linux 常用操作命令(CentOS 7.0)- 故障定位:服务器负载、进程管理、日志分析

    系统经研发测试上线后,如果运行期间出现了BUG,需要对服务故障进行定位,一般会查看服务器负载、服务状态、进程管理、服务日志等。 本文以CentOS 7.0 操作系统上的命令操作作为示例进行记录。 #服务器负载 完整参见:http://www.laobingbiji.com/note/detail.html?note_id=20231115154337

    2024年01月17日
    浏览(52)
  • 运维 | 查看 Linux 服务器 IP 地址

    大多数在操作 Linux 系统时,我们经常需要知道服务器的 IP 比便于后续的一系列操作,这时候有快速查看主机 IP 的命令行操作,能够有效的帮助我们 本章节主要记录一些常用查看服务器 IP 的命令,希望对大家有所帮助。 查看 Linux 服务器的 IP 地址的命令大体上有以下几种。

    2024年04月27日
    浏览(52)
  • Linux常用命令——ls命令

    显示目录内容列表 ls命令 用来显示目标列表,在Linux中是使用率较高的命令。ls命令的输出信息可以进行彩色加亮显示,以分区不同类型的文件。 语法 选项 参数 目录:指定要显示列表的目录,也可以是具体的文件。 实例 显示当前目录下包括影藏文件在内的所有文件列表 输

    2024年02月06日
    浏览(28)
  • 【运维】Linux 跨服务器复制文件文件夹

    如果是云服务 建议用内网ip scp是secure copy的简写,用于在Linux下进行远程拷贝文件的命令,和它类似的命令有cp,不过cp只是在本机进行拷贝不能跨服务器,而且scp传输是加密的。可能会稍微影响一下速度。当你服务器硬盘变为只读 read only system时,用scp可以帮你把文件移出来

    2024年02月08日
    浏览(46)
  • 【Linux 服务器运维】定时任务 crontab 详解 | 文末送书

    本文思维导图概述的主要内容: 1.1 什么是 crontab Crontab 是一个在 Unix 和 Linux 操作系统上 用于定时执行任务 的工具。它允许用户创建和管理计划任务,以便在特定的时间间隔或时间点自动运行命令或脚本。Crontab 是 cron table 的缩写, cron 指的是 Unix 系统中的一个后台进程,它

    2024年02月08日
    浏览(62)
  • 【Linux运维】shell脚本检查服务器内存和CPU利用率

    在管理服务器时候写了一个 shell脚本,在服务上实现每天凌晨3点查系统的指定文件夹下的容量大小,如果超过10G就要删除3天前的内容,还要时刻查询内存和cpu利用率,如果超过80%就要提示用户出现过载 将以上代码保存为一个.sh文件,然后通过crontab在每天凌晨3点运行即可:

    2024年02月09日
    浏览(48)
  • Linux服务器常见运维性能测试(1)综合跑分unixbench、superbench

    最近需要测试一批服务器的相关硬件性能,以及在常规环境下的硬件运行稳定情况,需要持续拷机测试稳定性。所以找了一些测试用例。本次测试包括在服务器的高低温下性能记录及压力测试,高低电压下性能记录及压力测试,常规环境下CPU满载稳定运行的功率记录。 这个系

    2024年02月04日
    浏览(55)
  • Linux本地部署1Panel服务器运维管理面板并实现公网访问

    1Panel 是一个现代化、开源的 Linux 服务器运维管理面板。高效管理,通过 Web 端轻松管理 Linux 服务器,包括主机监控、文件管理、数据库管理、容器管理等 下面我们介绍在Linux 本地安装1Panel 并结合cpolar 内网穿透工具实现远程访问1Panel 管理界面 执行如下命令一键安装 1Panel: 安

    2024年02月04日
    浏览(58)
  • openeuler服务器 ls 和ll 命令报错 command not found...

    在openeuler服务器执行 ls 和ll 命令报错 command not found...  大概是系统环境变量导致的问题。 我在安装redis是否没有安装成功后就出现了这样的情况。编辑profile文件没有写正确,导致在命令行下ls 和 ll 等命令不能够识别。 重新设置一下环境变量。 执行以后。  ll 命令可以使用

    2024年02月13日
    浏览(40)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包