Linux命令-ls

本文详细介绍了Linux中的ls命令,包括不带参数的基本用法,显示所有文件(包括隐藏文件)的选项,以长格式显示文件信息,按大小排序以及递归列出目录等内容。ls命令是Linux系统中用于查看目录内容的重要工具,通过不同的参数组合,可以实现对文件和目录的多种查看方式。
摘要由CSDN通过智能技术生成

ls

ls命令用于列出文件和目录。默认上,他会列出当前目录的内容。带上参数后,我们可以用ls做更多的事情。这里是一些在日常操作中使用到的ls用法的示例。
1.ls不带参数 列出文件或目录

[root@localhost ~]# ls
anaconda-ks.cfg       公共  视频  文档  音乐
initial-setup-ks.cfg  模板  图片  下载  桌面
[root@localhost ~]# ls -a
.                .bashrc    .ICEauthority         .tcshrc      文档
..               .cache     initial-setup-ks.cfg  .Xauthority  下载
anaconda-ks.cfg  .config    .lesshst              公共         音乐
.bash_history    .cshrc     .local                模板         桌面
.bash_logout     .dbus      .mozilla              视频
.bash_profile    .esd_auth  .pki                  图片

不带参数运行ls会只列出文件或者目录。看不到其他信息输出
2.ls -a 显示所有的,包括隐藏的文件

[root@localhost ~]# ls -a
.                .bashrc    .ICEauthority         .tcshrc      文档
..               .cache     initial-setup-ks.cfg  .Xauthority  下载
anaconda-ks.cfg  .config    .lesshst              公共         音乐
.bash_history    .cshrc     .local                模板         桌面
.bash_logout     .dbus      .mozilla              视频
.bash_profile    .esd_auth  .pki                  图片

3.ls -A 显示所有的,包括隐藏的文件或目录

[root@localhost ~]# ls -A
anaconda-ks.cfg  .config               .lesshst     公共  音乐
.bash_history    .cshrc                .local       模板  桌面
.bash_logout     .dbus                 .mozilla     视频
.bash_profile    .esd_auth             .pki         图片
.bashrc          .ICEauthority         .tcshrc      文档
.cache           initial-setup-ks.cfg  .Xauthority  下载

4.ls -l 列出长数据串,显示出文件的属性与权限等数据信息
缩写:ll

[root@localhost ~]# ls -l
总用量 8
-rw-------. 1 root root 1600 329 23:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1648 330 00:00 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 330 00:03 公共
drwxr-xr-x. 2 root root    6 330 00:03 模板
drwxr-xr-x. 2 root root    6 330 00:03 视频
drwxr-xr-x. 2 root root    6 330 00:03 图片
drwxr-xr-x. 2 root root    6 330 00:03 文档
drwxr-xr-x. 2 root root    6 330 00:03 下载
drwxr-xr-x. 2 root root    6 330 00:03 音乐
drwxr-xr-x. 2 root root    6 330 00:03 桌面

  • 第1列
    第一个字母d意味着内容是目录或者文件。如果是’-’(减号),这意味着它的内容是文件。当是l(小写l字符),意味这内容是链接文件。
    Linux的文件基本上分为三个属性:可读(r),可写(w),可执行(x)

  • 第2列 这行告诉我们有多少链接指向这个文件。

  • 第3列 这行告诉我们谁是这个文件/文件夹的所有者。

  • 第4列 这行告诉我们谁是这个文件/文件夹的所有组。

  • 第5列 这行告诉我们这个文件/文件夹的以字节为单位的大小。 目录的大小总是4096字节。

  • 第6列 这告诉我们文件最后的修改时间。

  • 第7列 这告诉我们文件名或者目录名。

5.ls -lh 显示文件大小

[root@localhost ~]# ls -lh
总用量 8.0K
-rw-------. 1 root root 1.6K 329 23:37 anaconda-ks.cfg
-rw-r--r--. 1 root root 1.7K 330 00:00 initial-setup-ks.cfg
drwxr-xr-x. 2 root root    6 330 00:03 公共
drwxr-xr-x. 2 root root    6 330 00:03 模板
drwxr-xr-x. 2 root root    6 330 00:03 视频
drwxr-xr-x. 2 root root    6 330 00:03 图片
drwxr-xr-x. 2 root root    6 330 00:03 文档
drwxr-xr-x. 2 root root    6 330 00:03 下载
drwxr-xr-x. 2 root root    6 330 00:03 音乐
drwxr-xr-x. 2 root root    6 330 00:03 桌面

*另外一个可以这么做的参数是–si。这个参数和-h参数类似,但是-si以1000为单位,而-h以1024

[root@localhost ~]# ls -si
总用量 8
537173186 4 anaconda-ks.cfg       537422411 0 图片
537173189 4 initial-setup-ks.cfg      81153 0 文档
807096981 0 公共                  269019619 0 下载
537422410 0 模板                  269019633 0 音乐
807096982 0 视频                      81094 0 桌面

6.ls -lhS 排序文件大小

[root@localhost ~]# ls -lhS
总用量 8.0K
-rw-r--r--. 1 root root 1.7K 330 00:00 initial-setup-ks.cfg
-rw-------. 1 root root 1.6K 329 23:37 anaconda-ks.cfg
drwxr-xr-x. 2 root root    6 330 00:03 公共
drwxr-xr-x. 2 root root    6 330 00:03 模板
drwxr-xr-x. 2 root root    6 330 00:03 视频
drwxr-xr-x. 2 root root    6 330 00:03 图片
drwxr-xr-x. 2 root root    6 330 00:03 文档
drwxr-xr-x. 2 root root    6 330 00:03 下载
drwxr-xr-x. 2 root root    6 330 00:03 音乐
drwxr-xr-x. 2 root root    6 330 00:03 桌面

7.ls -d */ 仅列出目录本身,而不是列出目录里的内容列表

[root@localhost ~]# ls -d */
公共/  模板/  视频/  图片/  文档/  下载/  音乐/  桌面/

8.ls -ld 单独看目录

dr-xr-x---. 16 root root 4096 423 13:43 .
[root@localhost ~]# cd /home
[root@localhost home]# ls -ld
drwxr-xr-x. 3 root root 17 330 00:02 .

9.ls -r 排序时反转顺序

[root@localhost /]# ls -r
usr  sys  sbin  root  opt  media  lib   etc  boot
var        tmp  srv  run   proc  mnt  lib64  home  dev  bin

ls -R 递归列出子目录
可以列出包含它子目录的目录。
**10.ls – lhr **

[root@localhost /]# ls -lhr
总用量 32K
drwxr-xr-x.  21 root root 4.0K 329 23:46 var
lrwxrwxrwx.   1 root root    8 329 23:29 sbin -> usr/sbin
drwxr-xr-x.   2 root root    6 411 2018 media
lrwxrwxrwx.   1 root root    9 329 23:29 lib64 -> usr/lib64
lrwxrwxrwx.   1 root root    7 329 23:29 lib -> usr/lib
drwxr-xr-x.   3 root root   17 330 00:02 home
drwxr-xr-x. 144 root root 8.0K 423 13:37 etc
drwxr-xr-x.  19 root root 3.3K 423 13:37 dev
lrwxrwxrwx.   1 root root    7 329 23:29 bin -> usr/bin

11.ls -…/ 列出父目录 列出1层之上的目录内容

[root@localhost /]# ls ../
bin   dev  home  lib64  mnt  proc  run   srv  tmp  var
boot  etc  lib   media  opt  root  sbin  sys  usr 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值