常用命令之ls 详解

ls详解

罗列目录内容权限,列出文件的信息列表(默认为当前目录)。

这个命令是Linux操作系统使用频率最高的命令,没有之一。熟练掌握这个命令的常用参数,可以提高学习、工作效率,因此需要认真对待。

1. 常用选项

– -a,–all:显示当前目录下全部文件(常用)

[root@jingz ~]# ls -a   
..bash_history  .bashrc  .cshrc.lesshst  .viminfo  .xauthVB71h5..   .bash_logout   .cache   .dbus .local.xauth3F8Xbp
anaconda-ks.cfg  .bash_profile  .config  initial-setup-ks.cfg  .tcshrc   .xauth3fbnpT

-A, –almost-all:显示当前目录下的所有文件但是不包括.和..这两个目录

[root@jingz ~]# ls -A
anaconda-ks.cfg  .bash_profile  .config  initial-setup-ks.cfg  .tcshrc       .xauth3fbnpT
.bash_history    .bashrc        .cshrc   .lesshst              .viminfo      .xauthVB71h5
.bash_logout     .cache         .dbus    .local                .xauth3F8Xbp

-l: 用长格式显示非隐藏文件,列出长数数据串,包含文件的属性与权限等(常用)

[root@jingz ~]# ls -l
total 8
-rw-------. 1 root root 1706 Jul 24 18:31 anaconda-ks.cfg
-rw-------. 1 root root 1754 Jul 24 09:56 initial-setup-ks.cfg

–author:和-l选项一起使用,显示出每个文件的作者

[root@jingz ~]# ls -l --author
total 8
-rw-------. 1 root root root 1706 Jul 24 18:31 anaconda-ks.cfg
-rw-------. 1 root root root 1754 Jul 24 09:56 initial-setup-ks.cfg

-d, –directory:仅仅列出目录本身,而不列出目录内的文件数据(常用)

[root@jingz ~]# ls -d /etc
/etc

-f :直接列出结果,而不进行排序(ls 默认以文件名排序)
-F :根据文件、目录等信息给予附加数据结构,例如: * 代表可执行文件; / 代表目录; = 代表 socket文件;| 代表 FIFO文件

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

这个命令现在用的不多因为现在有了颜色高亮,可以通过不同颜色来判断目录,文件等等;

蓝色文件———-目录

白色文件———-一般性文件,如文本文件,配置文件,源码文件等

浅蓝色文件———-链接文件,主要是使用ln命令建立的文件

绿色文件———-可执行文件,可执行的程序

红色文件———–压缩文件或者包文件

-h ,将文件容量以人类易读的方式(例如GB,KB等)列出来(常用)

[root@jingz ~]# ls -hl
total 12K
-rw-r--r--. 1 root root   54 Jul 30 17:23 123
-rw-------. 1 root root 1.7K Jul 24 18:31 anaconda-ks.cfg
-rw-------. 1 root root 1.8K Jul 24 09:56 initial-setup-ks.cfg

-i ,列出inode号码(常用)

[root@jingz ~]# ls -i
104432133 123  104922027 anaconda-ks.cfg  104428540 initial-setup-ks.cfg

-n 列出UID和GID

[root@jingz ~]# ls -n
total 12
-rw-r--r--. 1 0 0   54 Jul 30 17:23 123
-rw-------. 1 0 0 1706 Jul 24 18:31 anaconda-ks.cfg
-rw-------. 1 0 0 1754 Jul 24 09:56 initial-setup-ks.cfg

–full-time 以完整时间模式(包含年、月、日、时、分、秒)输出

[root@jingz ~]# ls --full-time 
total 12
-rw-r--r--. 1 root root   54 2016-07-30 17:23:01.531177259 +0800 123
-rw-------. 1 root root 1706 2016-07-24 18:31:24.384061072 +0800 anaconda-ks.cfg
-rw-------. 1 root root 1754 2016-07-24 09:56:04.952024819 +0800 initial-setup-ks.cfg

-r 将结果反向输出,例如原来是由大到小,现在就由小到大
-R 连同子目录下面的所有非隐藏文件都显示出来
-S 以文件容量大小排序,而不用文件名排序
-t –time=(ctime|atime)按照时间排序,而不是文件名

2. 常用组合

ll 是一个别名,是代表ls -l的意思

[root@jingz ~]# ll
    total 12
    -rw-r--r--. 1 root root   54 Jul 30 17:23 123
    -rw-------. 1 root root 1706 Jul 24 18:31 anaconda-ks.cfg
    -rw-------. 1 root root 1754 Jul 24 09:56 initial-setup-ks.cfg

ls -ld 显示当前目录的详细信息

[root@jingz ~]# ll -d
dr-xr-x---. 6 root root 4096 Jul 30 17:23 .

ls -al 列出当前目录的所有文件的详细信息

[root@jingz ~]# ls -al
total 76
dr-xr-x---.  6 root root  4096 Jul 30 17:23 .
dr-xr-xr-x. 18 root root  4096 Jul 27 11:13 ..
-rw-r--r--.  1 root root    54 Jul 30 17:23 123
-rw-------.  1 root root  1706 Jul 24 18:31 anaconda-ks.cfg
-rw-------.  1 root root 10329 Jul 30 18:32 .bash_history

ls -al –full-time :列出当前文件所有的详细信息及准确时间

[root@jingz ~]# ls --full-time  -al 
total 76
dr-xr-x---.  6 root root  4096 2016-07-30 17:23:01.518177258 +0800 .
dr-xr-xr-x. 18 root root  4096 2016-07-27 11:13:51.466531634 +0800 ..
-rw-r--r--.  1 root root    54 2016-07-30 17:23:01.531177259 +0800 123
-rw-------.  1 root root  1706 2016-07-24 18:31:24.384061072 +0800 anaconda-ks.cfg
-rw-------.  1 root root 10329 2016-07-30 18:32:56.663329844 +0800 .bash_history

ll -ahS 用人类可读的格式由大到小列出所有文件

[root@jingz ~]# ll -aSh
total 76
total 76K
-rw-------.  1 root root  11K Jul 30 18:32 .bash_history
-rw-------.  1 root root 4.8K Jul 30 11:10 .viminfo

原创文章,作者:fighter,如若转载,请注明出处:http://www.178linux.com/26924

(0)
fighterfighter
上一篇 2016-08-02 10:55
下一篇 2016-08-02 10:55

相关推荐

  • 第二十一周作业

    1、回顾并详细总结MySQL的存储引擎、索引; 常用存储引擎的对比: 特点 MyISAM InnoDB MEMORY MERGE NDB 存储限制 有 64TB 有 没有 有 事务安全 支持 锁机制 表锁 行锁 表锁 表锁 行锁 B树索引 支持 支持 支持 支持 支持 哈希索引 支持 全文索引 支持 集群索引 支持 数据缓存 支持 支持 支持 索引缓存 支持…

    2017-07-29
  • 第十八周博客作业

    1、为LNMP架构添加memcached支持,并完成对缓存效果的测试报告; 操作系统: CentOS 7.210.0.0.51 nginx+php+mysql10.0.0.52 memcached 一. 环境准备: 搭建LNMP编译安装环境 1. 配置163的yum源和阿里云的epel源 [root@localhost ~]# mv /etc/yum.rep…

    2017-07-12
  • N25期第五周作业

    1.显示当前系统上root、fedora或user1用户的默认shell grep -E ‘^(root|ftp|sync)’ /etc/passwd|cut -d: -f7 2.找出/etc/rc.d/init.d/functions文件中某单词后面跟一组小括号的行,形如:hello() grep ‘\b.*\b()’ /etc/rc.d/init.d/f…

    Linux干货 2016-12-26
  • LVM组件详解&创建实验流程

       前言:根据前面的学习我们知道,一个磁盘一旦分完区并且格式化后,其空间大小是没有办法进行调整了。因此推出了LVM(Logical Volume Manager)逻辑卷管理机制,LVM重点在于可以弹性的调整文件系统的容量!并非在于性能和数据保全方面,需要文件的读写性能或者数据的可靠性,需要用到RAID。而LVM可以整合多个物理…

    Linux干货 2016-08-30
  • Linux批量创建用户、passwd、shadow、组管理、group、gshadow、默认配置文件login.defs、切换用户su、提升权限(一)

    Linux批量创建用户、passwd、shadow、组管理、group、gshadow、默认配置文件login.defs、切换用户su、提升权限 在Linux中用户运行某个程序时,该程序的权限属于当前用户,进程所能够访问资源的权限取决于进程的运行者的身份。如果用户的id号为0,即使不叫root,他也是管理员;就算名字叫root它也可能是普通用户。当有多个不同…

    Linux干货 2016-08-03
  • while循环中的一个常见问题

    在楼主刚刚学习接触while循环的时候,发现了一个问题,在while循环内部对变量赋值、定义变量、数组定义等等环境,在循环外面失效。 一个简单的测试脚本如下: 执行结果证明,$new_var的结果是空值。在google上查了查,才发现问题出在管道上。 先看看下面的内容。 while循环的写法有好几种,它的语法结构为: while test_cmd_list;…

    2017-08-26